From d53c028f6bb34f6b593e8d948f82083d3cf500f4 Mon Sep 17 00:00:00 2001 From: hellekin Date: Fri, 25 Nov 2011 01:46:39 +0100 Subject: [PATCH] Rewrite slam_tomb() to use fuser, and replace missing dependency on lsof, by one on psmisc. --- debian/control | 2 +- src/tomb | 63 ++++++-------------------------------------------- 2 files changed, 8 insertions(+), 57 deletions(-) diff --git a/debian/control b/debian/control index 29f5d04b..2148333a 100644 --- a/debian/control +++ b/debian/control @@ -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 diff --git a/src/tomb b/src/tomb index 75740218..4731a01f 100755 --- a/src/tomb +++ b/src/tomb @@ -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