diff options
author | Patrick Ohly <patrick.ohly@intel.com> | 2011-11-26 20:33:34 +0000 |
---|---|---|
committer | Roger Leigh <rleigh@debian.org> | 2011-11-26 20:33:34 +0000 |
commit | f95e0b5ba03c5d54056ef7188d37dd3e9a63547e (patch) | |
tree | d8166dd667002144036e6ef19750cb13a59b960a /etc | |
parent | f72402876178d7adb143adf69b6b31c18a06e079 (diff) | |
download | schroot-f95e0b5ba03c5d54056ef7188d37dd3e9a63547e.tar.gz |
15killprocs: Warn about race condition when killing processes
Invoking /bin/kill on processes fails if the process already
quit by itself while the schroot shutdown runs. Because of "set -e"
this causes the whole shutdown to fail.
I have seen this occasionally in a nightly testing setup involving
a D-Bus session: when the D-Bus daemon stops, all other processes
depending on it also shut down automatically, with or without being
killed.
Diffstat (limited to 'etc')
-rwxr-xr-x | etc/setup.d/15killprocs | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/etc/setup.d/15killprocs b/etc/setup.d/15killprocs index 1f246b05..3b679f51 100755 --- a/etc/setup.d/15killprocs +++ b/etc/setup.d/15killprocs @@ -29,6 +29,17 @@ elif [ "$STATUS" = "ok" ]; then fatal "script-config file '$CHROOT_SCRIPT_CONFIG' does not exist" fi +# Wrapper around kill command. Turns errors into +# warnings when running in verbose mode, otherwise +# it ignores them. +# args: parameters for kill +kill_proc() +{ + if ! kill "$@" 2>/dev/null; then + info "kill $@ failed: process already terminated?" + fi +} + # Kill all processes that were run from within the chroot environment # $1: mount base location do_kill_all() @@ -51,7 +62,7 @@ do_kill_all() info "Killing left-over pid $pid (${exe##$1})" info " Sending SIGTERM to pid $pid" - /bin/kill -TERM "$pid" 2>/dev/null + kill_proc -TERM "$pid" count=0 max=5 @@ -62,7 +73,7 @@ do_kill_all() # Wait for $max seconds for process to die before -9'ing it if [ "$count" -eq "$max" ]; then info " Sending SIGKILL to pid $pid" - /bin/kill -KILL "$pid" 2>/dev/null + kill_proc -KILL "$pid" sleep 1 break fi @@ -74,4 +85,4 @@ do_kill_all() if [ $STAGE = "setup-recover" ] || [ $STAGE = "setup-stop" ]; then do_kill_all "$CHROOT_MOUNT_LOCATION" -fi
\ No newline at end of file +fi |