mirror of
https://github.com/Llewellynvdm/Tomb.git
synced 2024-11-20 03:30:59 +00:00
commit
f76a355fd0
95
src/tomb
95
src/tomb
@ -757,6 +757,67 @@ exec_safe_post_hooks() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
kill_tomb() {
|
||||||
|
# $1 = pids to kill
|
||||||
|
# $2 = type of kill
|
||||||
|
local e p
|
||||||
|
# substitute the \n with space
|
||||||
|
e=${1//$'\n'/ }
|
||||||
|
# split the string at space delim
|
||||||
|
# so we can get a for loop honestly
|
||||||
|
e=(${(s: :)e})
|
||||||
|
for p in $e; do
|
||||||
|
func "killing PID $p..."
|
||||||
|
if [[ "$2" == "soft" ]]; then
|
||||||
|
kill -USR1 $p
|
||||||
|
elif [[ "$2" == "hard" ]]; then
|
||||||
|
kill -TERM $p
|
||||||
|
elif [[ "$2" == "must die" ]]; then
|
||||||
|
kill -KILL $p
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
slam_tomb() {
|
||||||
|
# $1 = tomb mount point
|
||||||
|
local pidk
|
||||||
|
|
||||||
|
pidk=`lsof -t "$1"`
|
||||||
|
if [[ ! -z "$pidk" ]]; then
|
||||||
|
kill_tomb "$pidk" "soft"
|
||||||
|
else
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# if there are remaining pids
|
||||||
|
# we need to play hard
|
||||||
|
pidk=`lsof -t "$1"`
|
||||||
|
if [[ -z "$pidk" ]]; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# if we set the -f (force) option
|
||||||
|
# don't wait, just kill
|
||||||
|
option_is_set -f || sleep 3
|
||||||
|
kill_tomb "$pidk" "hard"
|
||||||
|
pidk=`lsof -t "$1"`
|
||||||
|
if [[ -z "$pidk" ]]; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# if there are still some pids around
|
||||||
|
# we have to kill 'em all
|
||||||
|
option_is_set -f || sleep 3
|
||||||
|
kill_tomb "$pidk" "must die"
|
||||||
|
pidk=`lsof -t "$1"`
|
||||||
|
if [[ -z "$pidk" ]]; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# what PITA!
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
umount_tomb() {
|
umount_tomb() {
|
||||||
local tombs how_many_tombs
|
local tombs how_many_tombs
|
||||||
local pathmap mapper tombname tombmount loopdev
|
local pathmap mapper tombname tombmount loopdev
|
||||||
@ -765,10 +826,10 @@ umount_tomb() {
|
|||||||
if ! [ $1 ]; then
|
if ! [ $1 ]; then
|
||||||
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.*'`
|
||||||
func "closing mapper $tombs"
|
func "closing mapper $tombs"
|
||||||
umount_tomb ${tombs}
|
umount_tomb ${tombs}
|
||||||
@ -798,26 +859,20 @@ umount_tomb() {
|
|||||||
pathmap=`dirname "$1"`
|
pathmap=`dirname "$1"`
|
||||||
|
|
||||||
if [ "${pathmap}" = "/dev/mapper" ]; then
|
if [ "${pathmap}" = "/dev/mapper" ]; then
|
||||||
|
|
||||||
mapper="$1" # argument is the mapper (or none which autofills mapper)
|
mapper="$1" # argument is the mapper (or none which autofills mapper)
|
||||||
tombname="`print $mapper | cut -d. -f2`"
|
tombname="`print $mapper | cut -d. -f2`"
|
||||||
tombmount=`mount -l | \
|
tombmount=`mount -l | \
|
||||||
awk -vtomb="[$tombname]" '/^\/dev\/mapper\/tomb/ { if($7==tomb) print $3 } '`
|
awk -vtomb="[$tombname]" '/^\/dev\/mapper\/tomb/ { if($7==tomb) print $3 } '`
|
||||||
|
|
||||||
elif [ "$pathmap" = "." ]; then
|
elif [ "$pathmap" = "." ]; then
|
||||||
|
|
||||||
tombname="$1" # argument is the name
|
tombname="$1" # argument is the name
|
||||||
mapper=`mount -l | \
|
mapper=`mount -l | \
|
||||||
awk -vtomb="[$tombname]" '/^\/dev\/mapper\/tomb/ { if($7==tomb) print $1 } '`
|
awk -vtomb="[$tombname]" '/^\/dev\/mapper\/tomb/ { if($7==tomb) print $1 } '`
|
||||||
tombmount=`mount -l | \
|
tombmount=`mount -l | \
|
||||||
awk -vtomb="[$tombname]" '/^\/dev\/mapper\/tomb/ { if($7==tomb) print $3 } '`
|
awk -vtomb="[$tombname]" '/^\/dev\/mapper\/tomb/ { if($7==tomb) print $3 } '`
|
||||||
|
|
||||||
else
|
else
|
||||||
|
|
||||||
tombmount="$1" # argument should be the mount
|
tombmount="$1" # argument should be the mount
|
||||||
mapper=`mount | awk -vmnt="$tombmount" '/^\/dev\/mapper\/tomb/ { if($3==mnt) print $1 }'`
|
mapper=`mount | awk -vmnt="$tombmount" '/^\/dev\/mapper\/tomb/ { if($3==mnt) print $1 }'`
|
||||||
tombname="`print $mapper | cut -d. -f2`"
|
tombname="`print $mapper | cut -d. -f2`"
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# avoid block when the same tomb is mounted, take only the first
|
# avoid block when the same tomb is mounted, take only the first
|
||||||
@ -837,12 +892,11 @@ umount_tomb() {
|
|||||||
if [ $SLAM ]; then
|
if [ $SLAM ]; then
|
||||||
notice "Slamming tomb $tombname mounted on $tombmount"
|
notice "Slamming tomb $tombname mounted on $tombmount"
|
||||||
act "Kill all processes busy inside the tomb"
|
act "Kill all processes busy inside the tomb"
|
||||||
pidk=`lsof -t "$tombmount"`
|
slam_tomb "$tombmount"
|
||||||
for p in "$pidk"; do
|
if [[ $? == 1 ]]; then
|
||||||
pname=`pidof $p`
|
error "Cannot slam the tomb $tombname"
|
||||||
func "killing PID $p of $pname..."
|
return 1
|
||||||
kill -9 $p
|
fi
|
||||||
done
|
|
||||||
else
|
else
|
||||||
notice "Closing tomb $tombname mounted on $tombmount"
|
notice "Closing tomb $tombname mounted on $tombmount"
|
||||||
fi
|
fi
|
||||||
@ -854,15 +908,14 @@ umount_tomb() {
|
|||||||
hook="`basename $b`"
|
hook="`basename $b`"
|
||||||
act "closing tomb hook: $hook"
|
act "closing tomb hook: $hook"
|
||||||
umount $b
|
umount $b
|
||||||
if ! [ $? = 0 ]; then
|
if [[ $? != 0 ]]; then
|
||||||
if [ $SLAM ]; then
|
if [ $SLAM ]; then
|
||||||
notice "Slamming tomb: killing all processes using this hook"
|
notice "Slamming tomb: killing all processes using this hook"
|
||||||
pidk=`lsof -t $b`
|
slam_tomb "$b"
|
||||||
for p in "$pidk"; do
|
if [[ $? == 1 ]]; then
|
||||||
pname=`pidof $p`
|
error "Cannot slam the tomb $b"
|
||||||
notice "Killing PID $p of $pname..."
|
return 1
|
||||||
kill -9 $p
|
fi
|
||||||
done
|
|
||||||
umount $b
|
umount $b
|
||||||
else
|
else
|
||||||
error "Tomb hook is busy, cannot close tomb."
|
error "Tomb hook is busy, cannot close tomb."
|
||||||
|
Loading…
Reference in New Issue
Block a user