mirror of
https://github.com/Llewellynvdm/Tomb.git
synced 2024-11-05 04:47:56 +00:00
fixes to tomb close
This commit is contained in:
parent
8771d103b7
commit
449d6ae61a
95
src/tomb
95
src/tomb
@ -643,15 +643,15 @@ umount_tomb() {
|
|||||||
tombs=`find /dev/mapper -name 'tomb.*'`
|
tombs=`find /dev/mapper -name 'tomb.*'`
|
||||||
how_many_tombs=`wc -w <<< "$tombs"`
|
how_many_tombs=`wc -w <<< "$tombs"`
|
||||||
if [ "$how_many_tombs" = "0" ]; then
|
if [ "$how_many_tombs" = "0" ]; then
|
||||||
error "there is no open tomb to be closed"
|
error "There is no open tomb to be closed"
|
||||||
return 1
|
return 1
|
||||||
elif [ "$how_many_tombs" = "1" ]; then
|
elif [ "$how_many_tombs" = "1" ]; then
|
||||||
#mapper=`find /dev/mapper -name 'tomb.*'`
|
#mapper=`find /dev/mapper -name 'tomb.*'`
|
||||||
notice "trying to close $tombs"
|
notice "Closing $tombs"
|
||||||
umount_tomb ${tombs}
|
umount_tomb ${tombs}
|
||||||
return 1
|
return 1
|
||||||
else
|
else
|
||||||
error "too many tombs mounted, please specify which to unmount:"
|
error "Too many tombs mounted, please specify which to unmount:"
|
||||||
ls /dev/mapper/tomb.*
|
ls /dev/mapper/tomb.*
|
||||||
error "or issue the command 'tomb close all' to clos'em all."
|
error "or issue the command 'tomb close all' to clos'em all."
|
||||||
return 1
|
return 1
|
||||||
@ -670,41 +670,81 @@ umount_tomb() {
|
|||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! [ -e "$1" ]; then
|
|
||||||
error "tomb not found: $1"
|
# tomb close argument deduction
|
||||||
error "Please specify an existing tomb"
|
pathmap=`dirname "$1"`
|
||||||
|
|
||||||
|
if [ "${pathmap}" = "/dev/mapper" ]; then
|
||||||
|
|
||||||
|
mapper="$1" # argument is the mapper (or none which autofills mapper)
|
||||||
|
tombname="`echo $mapper | cut -d. -f2`"
|
||||||
|
tombmount=`mount -l | \
|
||||||
|
awk -vtomb="[$tombname]" '/^\/dev\/mapper\/tomb/ { if($7==tomb) print $3 } '`
|
||||||
|
|
||||||
|
elif [ "$pathmap" = "." ]; then
|
||||||
|
|
||||||
|
tombname="$1" # argument is the name
|
||||||
|
mapper=`mount -l | \
|
||||||
|
awk -vtomb="[$tombname]" '/^\/dev\/mapper\/tomb/ { if($7==tomb) print $1 } '`
|
||||||
|
tombmount=`mount -l | \
|
||||||
|
awk -vtomb="[$tombname]" '/^\/dev\/mapper\/tomb/ { if($7==tomb) print $3 } '`
|
||||||
|
|
||||||
|
else
|
||||||
|
|
||||||
|
tombmount="$1" # argument should be the mount
|
||||||
|
mapper=`mount | awk -vmnt="$tombmount" '/^\/dev\/mapper\/tomb/ { if($3==mnt) print $1 }'`
|
||||||
|
tombname="`echo $mapper | cut -d. -f2`"
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
|
func "tomb close argument: $1"
|
||||||
|
func "name:\t$tombname"
|
||||||
|
func "mount:\t$tombmount"
|
||||||
|
func "mapper:\t$mapper"
|
||||||
|
|
||||||
|
if ! [ -e "$mapper" ]; then
|
||||||
|
error "Tomb not found: $1"
|
||||||
|
error "Please specify an existing tomb."
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
pathmap=`dirname "$1"`
|
if [ $SLAM ]; then
|
||||||
if [ "${pathmap}" = "/dev/mapper" ]; then
|
notice "Slamming tomb $tombname mounted on $tombmount"
|
||||||
mapper="$1" # $1 is /dev/mapper/tomb.*
|
act "Kill all processes busy inside the tomb"
|
||||||
tombname=`basename "$1"` # this is tomb.NAME.XXX.loopX
|
|
||||||
tombmount=`mount | grep "$mapper" | awk -F ' ' '{print $3}'` # tomb mount point
|
|
||||||
else
|
else
|
||||||
tombmount="$1" # $1 is the tomb mount point (e.g. /mnt)
|
notice "Closing tomb $tombname mounted on $tombmount"
|
||||||
mapper=`mount | grep -w "${tombmount%%/}" | awk -F ' ' '{print $1}'`
|
|
||||||
tombname=`basename "$mapper"` # this is tomb.NAME.XXX.loopX
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# check if there are binded dirs and close them first
|
# check if there are binded dirs and close them first
|
||||||
mount | grep "${tombmount%%/}" 2>/dev/null | grep -v loop 2>&1 > /dev/null
|
tombmount_esc="`echo ${tombmount} | sed 's:\/:\\\/:g'`"
|
||||||
if [ $? = 0 ]; then
|
unbind=`mount | awk "/^$tombmount_esc.*bind/"' { print $3 }'`
|
||||||
act "closing bind hooks for tomb $tombname "
|
for b in ${(f)unbind}; do
|
||||||
unbind=`mount | grep ${tombmount%%/} | grep -v loop | awk '
|
hook="`basename $b`"
|
||||||
{ print "umount " $3 "; " }
|
act "closing tomb hook: $hook"
|
||||||
'`
|
umount $b
|
||||||
eval $unbind
|
if ! [ $? = 0 ]; then
|
||||||
func "umount binded dirs:"
|
if [ $SLAM ]; then
|
||||||
func "$unbind"
|
notice "Slamming tomb: killing all processes using this hook"
|
||||||
|
pidk=`lsof -t $b`
|
||||||
|
for p in "$pidk"; do
|
||||||
|
pname=`pidof $p`
|
||||||
|
notice "Killing PID $p of $pname..."
|
||||||
|
kill -9 $p
|
||||||
|
done
|
||||||
|
umount $b
|
||||||
|
else
|
||||||
|
error "Tomb hook is busy, cannot close tomb."
|
||||||
|
return 1
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
# Execute post-hooks for eventual cleanup
|
# Execute post-hooks for eventual cleanup
|
||||||
if ! [ $NOBIND ]; then
|
if ! [ $NOBIND ]; then
|
||||||
exec_safe_post_hooks ${tombmount%%/} close
|
exec_safe_post_hooks ${tombmount%%/} close
|
||||||
fi
|
fi
|
||||||
|
|
||||||
act "closing tomb $tombname on dm-crypt $tombmount"
|
if [ $tombmount ]; then # tomb is actively mounted
|
||||||
|
act "closing tomb $tombname mounted on $tombmount"
|
||||||
umount ${tombmount} 2> /dev/null
|
umount ${tombmount} 2> /dev/null
|
||||||
if ! [ $? = 0 ]; then
|
if ! [ $? = 0 ]; then
|
||||||
error "Tomb is busy, cannot umount!"
|
error "Tomb is busy, cannot umount!"
|
||||||
@ -722,14 +762,15 @@ umount_tomb() {
|
|||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
cryptsetup luksClose $tombname
|
cryptsetup luksClose $mapper
|
||||||
if ! [ $? = 0 ]; then
|
if ! [ $? = 0 ]; then
|
||||||
error "error occurred in cryptsetup luksClose ${mapper}"
|
error "error occurred in cryptsetup luksClose ${mapper}"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
loopdev=`cut -d '.' -f4 <<< "$tombname"`
|
loopdev=`cut -d '.' -f4 <<< "$mapper"`
|
||||||
losetup -d "/dev/$loopdev"
|
losetup -d "/dev/$loopdev"
|
||||||
|
|
||||||
notice "Tomb $tombname closed: your bones will rest in peace."
|
notice "Tomb $tombname closed: your bones will rest in peace."
|
||||||
|
Loading…
Reference in New Issue
Block a user