forked from pool/pam_mount
42 lines
1.2 KiB
Plaintext
42 lines
1.2 KiB
Plaintext
Index: scripts/umount.crypt
|
|
===================================================================
|
|
--- scripts/umount.crypt.orig
|
|
+++ scripts/umount.crypt
|
|
@@ -58,6 +58,7 @@ fi;
|
|
# ask cryptsetup about the underlying device
|
|
#
|
|
REALDEVICE=`cryptsetup status "$DMDEVICE" | sed -n '/device/s/[ ]*device:[ ]*//p'`;
|
|
+IMGDEVICE=`"$LOSETUP" -a | grep "$REALDEVICE" | awk -F\( '{ print $2 }' | sed 's/)//'`
|
|
|
|
for ((x = 5; x >= 0; --x)); do
|
|
fuser -m "$1" || break;
|
|
@@ -65,6 +66,15 @@ for ((x = 5; x >= 0; --x)); do
|
|
sleep 1;
|
|
done;
|
|
|
|
+# kill remaining user processes if we're unmounting a user's home dir
|
|
+USER=`stat --format=%U $1 2>/dev/null` && getent passwd "$USER" | grep -e ":$1:" &> /dev/null
|
|
+if test $? -eq 0; then
|
|
+ lsof -t $1 | xargs kill -TERM &> /dev/null
|
|
+ sleep 1
|
|
+ lsof -t $1 | xargs kill -9 &> /dev/null
|
|
+ sleep 1
|
|
+fi
|
|
+
|
|
umount "$1";
|
|
if [ $? -ne 0 ]; then
|
|
echo "${0##*/}: error unmounting $1" >&2
|
|
@@ -85,3 +95,12 @@ if echo "$REALDEVICE" | grep ^/dev/loop
|
|
exit 1
|
|
fi
|
|
fi
|
|
+
|
|
+if echo "$IMGDEVICE" | grep ^/dev/loop >/dev/null; then
|
|
+ "$LOSETUP" -d "$IMGDEVICE";
|
|
+ if [ $? -ne 0 ]; then
|
|
+ echo "${0##*/}: error removing $IMGDEVICE" >&2
|
|
+ exit 1
|
|
+ fi
|
|
+fi
|
|
+
|