From: Harald Hoyer Date: Fri, 18 Jan 2013 12:46:30 +0000 (+0100) Subject: shutdown: kill all processes and report remaining ones X-Git-Tag: 025~11 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=551c2dd71f790668213210998c53dd3ce0274159;p=thirdparty%2Fdracut.git shutdown: kill all processes and report remaining ones --- diff --git a/modules.d/99base/dracut-lib.sh b/modules.d/99base/dracut-lib.sh index 83ac68f66..15f13c3e4 100755 --- a/modules.d/99base/dracut-lib.sh +++ b/modules.d/99base/dracut-lib.sh @@ -43,6 +43,20 @@ str_replace() { echo "${out}${in}" } +killall_proc_mountpoint() { + local _pid + local _t + for _pid in /proc/*; do + _pid=${_pid##/proc/} + case $_pid in + *[!0-9]*) continue;; + esac + [ -e /proc/$_pid/exe ] || continue + [ -e /proc/$_pid/root ] || continue + strstr "$(ls -l /proc/$_pid /proc/$_pid/fd 2>/dev/null)" "$1" && kill -9 $_pid + done +} + _getcmdline() { local _line local _i diff --git a/modules.d/99shutdown/shutdown.sh b/modules.d/99shutdown/shutdown.sh index acd3bfe6f..bab81f209 100755 --- a/modules.d/99shutdown/shutdown.sh +++ b/modules.d/99shutdown/shutdown.sh @@ -8,6 +8,8 @@ # Harald Hoyer ACTION="$1" +exec >/dev/console 2>>/dev/console + export TERM=linux export PATH=/usr/sbin:/usr/bin:/sbin:/bin . /lib/dracut-lib.sh @@ -26,7 +28,13 @@ getarg 'rd.break=pre-shutdown' && emergency_shell --shutdown pre-shutdown "Break source_hook pre-shutdown -/bin/plymouth --quit || /oldroot/bin/plymouth --quit +if ! ( [ -x /bin/plymouth ] && /bin/plymouth --quit ); then + [ -x /oldroot/bin/plymouth ] && /oldroot/bin/plymouth --quit +fi + +warn "Killing all remaining processes" + +killall_proc_mountpoint /oldroot umount_a() { local _did_umount="n" @@ -34,7 +42,7 @@ umount_a() { if strstr "$mp" oldroot; then if umount "$mp"; then _did_umount="y" - echo "Unmounted $mp." + warn "Unmounted $mp." fi fi done /dev/null || break _cnt=$(($_cnt+1)) done + [ $_cnt -ge 40 ] && umount_a +if strstr "$(cat /proc/mounts)" "/oldroot"; then + warn "Cannot umount /oldroot" + for _pid in /proc/*; do + _pid=${_pid##/proc/} + case $_pid in + *[!0-9]*) continue;; + esac + [ -e /proc/$_pid/exe ] || continue + [ -e /proc/$_pid/root ] || continue + if strstr "$(ls -l /proc/$_pid /proc/$_pid/fd 2>/dev/null)" "oldroot"; then + warn "Blocking umount of /oldroot [$_pid] $(cat /proc/$_pid/cmdline)" + elif [ $_pid -ne $$ ]; then + warn "Still running [$_pid] $(cat /proc/$_pid/cmdline)" + fi + ls -l /proc/$_pid/fd 2>&1 | vwarn + done +fi + _check_shutdown() { local __f local __s=1