shutdown: kill all processes and report remaining ones
authorHarald Hoyer <harald@redhat.com>
Fri, 18 Jan 2013 12:46:30 +0000 (13:46 +0100)
committerHarald Hoyer <harald@redhat.com>
Tue, 22 Jan 2013 14:31:45 +0000 (15:31 +0100)
modules.d/99base/dracut-lib.sh
modules.d/99shutdown/shutdown.sh

index 83ac68f..15f13c3 100755 (executable)
@@ -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
index acd3bfe..bab81f2 100755 (executable)
@@ -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