From 13076991a94a303ff35fdca06180b7c3c04d4813 Mon Sep 17 00:00:00 2001
From: Harald Hoyer <harald@redhat.com>
Date: Fri, 18 Jan 2013 13:46:30 +0100
Subject: [PATCH] shutdown: kill all processes and report remaining ones
---
modules.d/99base/dracut-lib.sh | 14 ++++++++++++++
modules.d/99shutdown/shutdown.sh | 31 +++++++++++++++++++++++++++++--
2 files changed, 43 insertions(+), 2 deletions(-)
diff --git a/modules.d/99base/dracut-lib.sh b/modules.d/99base/dracut-lib.sh
index 4094f70..c2ecfb3 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 acd3bfe..bab81f2 100755
--- a/modules.d/99shutdown/shutdown.sh
+++ b/modules.d/99shutdown/shutdown.sh
@@ -8,6 +8,8 @@
# Harald Hoyer <harald@redhat.com>
ACTION="$1"
+exec </dev/console >>/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 </proc/mounts
@@ -47,8 +55,27 @@ while [ $_cnt -le 40 ]; do
umount_a 2>/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