Skip to content

Commit

Permalink
Rewrite slam_tomb() to use fuser, and replace missing dependency on l…
Browse files Browse the repository at this point in the history
…sof, by one on psmisc.
  • Loading branch information
hellekin committed Nov 25, 2011
1 parent 1b4c08e commit d53c028
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 57 deletions.
2 changes: 1 addition & 1 deletion debian/control
Expand Up @@ -8,7 +8,7 @@ Homepage: http://tomb.dyne.org

Package: tomb
Architecture: any
Depends: ${shlibs:Depends}, ${misc:Depends}, zsh, cryptsetup, pinentry-curses, gnupg, sudo
Depends: ${shlibs:Depends}, ${misc:Depends}, zsh, cryptsetup, pinentry-curses, gnupg, sudo, psmisc
Suggests: tomb-gtk, wipe, dcfldd, steghide
Description: the crypto undertaker
Derived from the dyne:bolic nesting mechanism, Tomb is a free and
Expand Down
63 changes: 7 additions & 56 deletions src/tomb
Expand Up @@ -777,66 +777,17 @@ exec_safe_post_hooks() {
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
# Kill all processes using the tomb
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!
for s in INT TERM HUP KILL; do
fuser -s -m "$1" || return 0
fuser -s -m "$1" -k -M -$s && { option_is_set -f || sleep 3 }
done
return 1
}
# }}}

umount_tomb() {
local tombs how_many_tombs
Expand Down

0 comments on commit d53c028

Please sign in to comment.