Blame 0005-shutdown-use-emergency_shell-from-dracut-lib.patch

Harald Hoyer ab65ae
From bd3bf2ce41379459e79b9f48027d457caecce30a Mon Sep 17 00:00:00 2001
Harald Hoyer ab65ae
From: Will Woods <wwoods@redhat.com>
Harald Hoyer ab65ae
Date: Thu, 5 Apr 2012 13:01:39 -0400
Harald Hoyer ab65ae
Subject: [PATCH] shutdown: use emergency_shell from dracut-lib
Harald Hoyer ab65ae
Harald Hoyer ab65ae
---
Harald Hoyer ab65ae
 modules.d/99base/dracut-lib.sh   |   10 ++++----
Harald Hoyer ab65ae
 modules.d/99shutdown/shutdown.sh |   47 +++-----------------------------------
Harald Hoyer ab65ae
 2 files changed, 9 insertions(+), 48 deletions(-)
Harald Hoyer ab65ae
Harald Hoyer ab65ae
diff --git a/modules.d/99base/dracut-lib.sh b/modules.d/99base/dracut-lib.sh
Harald Hoyer ab65ae
index e10a34d..a29d586 100755
Harald Hoyer ab65ae
--- a/modules.d/99base/dracut-lib.sh
Harald Hoyer ab65ae
+++ b/modules.d/99base/dracut-lib.sh
Harald Hoyer ab65ae
@@ -767,15 +767,17 @@ emergency_shell()
Harald Hoyer ab65ae
 {
Harald Hoyer ab65ae
     local _ctty
Harald Hoyer ab65ae
     set +e
Harald Hoyer ab65ae
+    local _rdshell_name="dracut" action="Boot" hook="emergency"
Harald Hoyer ab65ae
     if [ "$1" = "-n" ]; then
Harald Hoyer ab65ae
         _rdshell_name=$2
Harald Hoyer ab65ae
         shift 2
Harald Hoyer ab65ae
-    else
Harald Hoyer ab65ae
-        _rdshell_name=dracut
Harald Hoyer ab65ae
+    elif [ "$1" = "--shutdown" ]; then
Harald Hoyer ab65ae
+        _rdshell_name=$2; action="Shutdown"; hook="shutdown-emergency"
Harald Hoyer ab65ae
+        shift 2
Harald Hoyer ab65ae
     fi
Harald Hoyer ab65ae
     echo ; echo
Harald Hoyer ab65ae
     warn $@
Harald Hoyer ab65ae
-    source_hook emergency
Harald Hoyer ab65ae
+    source_hook "$hook"
Harald Hoyer ab65ae
     echo
Harald Hoyer ab65ae
     wait_for_loginit
Harald Hoyer ab65ae
     [ -e /run/initramfs/.die ] && exit 1
Harald Hoyer ab65ae
@@ -798,7 +800,7 @@ emergency_shell()
Harald Hoyer ab65ae
         strstr "$(setsid --help 2>/dev/null)" "ctty" && CTTY="-c"
Harald Hoyer ab65ae
         setsid $CTTY /bin/sh -i -l 0<$_ctty 1>$_ctty 2>&1
Harald Hoyer ab65ae
     else
Harald Hoyer ab65ae
-        warn "Boot has failed. To debug this issue add \"rdshell\" to the kernel command line."
Harald Hoyer ab65ae
+        warn "$action has failed. To debug this issue add \"rd.shell\" to the kernel command line."
Harald Hoyer ab65ae
         # cause a kernel panic
Harald Hoyer ab65ae
         exit 1
Harald Hoyer ab65ae
     fi
Harald Hoyer ab65ae
diff --git a/modules.d/99shutdown/shutdown.sh b/modules.d/99shutdown/shutdown.sh
Harald Hoyer ab65ae
index 8817a4c..45345a4 100755
Harald Hoyer ab65ae
--- a/modules.d/99shutdown/shutdown.sh
Harald Hoyer ab65ae
+++ b/modules.d/99shutdown/shutdown.sh
Harald Hoyer ab65ae
@@ -12,49 +12,8 @@
Harald Hoyer ab65ae
 export TERM=linux
Harald Hoyer ab65ae
 PATH=/usr/sbin:/usr/bin:/sbin:/bin
Harald Hoyer ab65ae
 
Harald Hoyer ab65ae
-emergency_shell()
Harald Hoyer ab65ae
-{
Harald Hoyer ab65ae
-    local _ctty
Harald Hoyer ab65ae
-    set +e
Harald Hoyer ab65ae
-    if [ "$1" = "-n" ]; then
Harald Hoyer ab65ae
-        _rdshell_name=$2
Harald Hoyer ab65ae
-        shift 2
Harald Hoyer ab65ae
-    else
Harald Hoyer ab65ae
-        _rdshell_name=dracut
Harald Hoyer ab65ae
-    fi
Harald Hoyer ab65ae
-    echo ; echo
Harald Hoyer ab65ae
-    warn $@
Harald Hoyer ab65ae
-    source_hook shutdown-emergency
Harald Hoyer ab65ae
-    echo
Harald Hoyer ab65ae
-    if getargbool 1 rd.shell -y rdshell || getarg rd.break rdbreak; then
Harald Hoyer ab65ae
-        echo "Dropping to debug shell."
Harald Hoyer ab65ae
-        echo
Harald Hoyer ab65ae
-        export PS1="$_rdshell_name:\${PWD}# "
Harald Hoyer ab65ae
-        [ -e /.profile ] || >/.profile
Harald Hoyer ab65ae
-
Harald Hoyer ab65ae
-        _ctty="$(getarg rd.ctty=)" && _ctty="/dev/${_ctty##*/}"
Harald Hoyer ab65ae
-        if [ -z "$_ctty" ]; then
Harald Hoyer ab65ae
-            _ctty=console
Harald Hoyer ab65ae
-            while [ -f /sys/class/tty/$_ctty/active ]; do
Harald Hoyer ab65ae
-                _ctty=$(cat /sys/class/tty/$_ctty/active)
Harald Hoyer ab65ae
-                _ctty=${_ctty##* } # last one in the list
Harald Hoyer ab65ae
-            done
Harald Hoyer ab65ae
-            _ctty=/dev/$_ctty
Harald Hoyer ab65ae
-        fi
Harald Hoyer ab65ae
-        [ -c "$_ctty" ] || _ctty=/dev/tty1
Harald Hoyer ab65ae
-        strstr "$(setsid --help)" "control" && CTTY="-c"
Harald Hoyer ab65ae
-        setsid $CTTY /bin/sh -i -l 0<$_ctty 1>$_ctty 2>&1
Harald Hoyer ab65ae
-    else
Harald Hoyer ab65ae
-        exec /lib/systemd/systemd-shutdown "$@"
Harald Hoyer ab65ae
-        warn "Shutdown has failed. To debug this issue add \"rdshell\" to the kernel command line."
Harald Hoyer ab65ae
-        # cause a kernel panic
Harald Hoyer ab65ae
-        exit 1
Harald Hoyer ab65ae
-    fi
Harald Hoyer ab65ae
-}
Harald Hoyer ab65ae
-
Harald Hoyer ab65ae
-trap "emergency_shell Signal caught!" 0
Harald Hoyer ab65ae
-
Harald Hoyer ab65ae
-getarg 'rd.break=pre-shutdown' && emergency_shell -n cmdline "Break before pre-shutdown"
Harald Hoyer ab65ae
+trap "emergency_shell --shutdown shutdown Signal caught!" 0
Harald Hoyer ab65ae
+getarg 'rd.break=pre-shutdown' && emergency_shell --shutdown pre-shutdown "Break before pre-shutdown"
Harald Hoyer ab65ae
 
Harald Hoyer ab65ae
 umount_a() {
Harald Hoyer ab65ae
     local _did_umount="n"
Harald Hoyer ab65ae
@@ -97,7 +56,7 @@ while _check_shutdown; do
Harald Hoyer ab65ae
 done
Harald Hoyer ab65ae
 _check_shutdown final
Harald Hoyer ab65ae
 
Harald Hoyer ab65ae
-getarg 'rd.break=shutdown' && emergency_shell -n cmdline "Break before shutdown"
Harald Hoyer ab65ae
+getarg 'rd.break=shutdown' && emergency_shell --shutdown shutdown "Break before shutdown"
Harald Hoyer ab65ae
 [ "$1" = "reboot" ] && reboot -f -d -n --no-wall
Harald Hoyer ab65ae
 [ "$1" = "poweroff" ] && poweroff -f -d -n --no-wall
Harald Hoyer ab65ae
 [ "$1" = "halt" ] && halt -f -d -n --no-wall