Blame 0105-add-rd.emergency-reboot-poweroff-halt.patch

Harald Hoyer 414eba
From c45e856a659a37537c107f7ef3e680abf60a96a5 Mon Sep 17 00:00:00 2001
Harald Hoyer 414eba
From: Harald Hoyer <harald@redhat.com>
Harald Hoyer 414eba
Date: Fri, 22 Jul 2016 13:32:47 +0200
Harald Hoyer 414eba
Subject: [PATCH] add rd.emergency=[reboot|poweroff|halt]
Harald Hoyer 414eba
Harald Hoyer 414eba
specifies what action to execute in case of a critical failure
Harald Hoyer 414eba
---
Harald Hoyer 414eba
 dracut.cmdline.7.asc                           |  3 +++
Harald Hoyer 414eba
 modules.d/98dracut-systemd/dracut-emergency.sh | 13 +++++++++++--
Harald Hoyer 414eba
 modules.d/99base/dracut-lib.sh                 | 24 ++++++++++++++++--------
Harald Hoyer 414eba
 3 files changed, 30 insertions(+), 10 deletions(-)
Harald Hoyer 414eba
Harald Hoyer 414eba
diff --git a/dracut.cmdline.7.asc b/dracut.cmdline.7.asc
Harald Hoyer 414eba
index bf00719..a2d1f95 100644
Harald Hoyer 414eba
--- a/dracut.cmdline.7.asc
Harald Hoyer 414eba
+++ b/dracut.cmdline.7.asc
Harald Hoyer 414eba
@@ -129,6 +129,9 @@ menuentry 'Live Fedora 20' --class fedora --class gnu-linux --class gnu --class
Harald Hoyer 414eba
 
Harald Hoyer 414eba
 Misc
Harald Hoyer 414eba
 ~~~~
Harald Hoyer 414eba
+**rd.emergency=**__[reboot|poweroff|halt]__::
Harald Hoyer 414eba
+    specify, what action to execute in case of a critical failure.
Harald Hoyer 414eba
+
Harald Hoyer 414eba
 **rd.driver.blacklist=**__<drivername>__[,__<drivername>__,...]::
Harald Hoyer 414eba
     do not load kernel module <drivername>. This parameter can be specified
Harald Hoyer 414eba
     multiple times.
Harald Hoyer 414eba
diff --git a/modules.d/98dracut-systemd/dracut-emergency.sh b/modules.d/98dracut-systemd/dracut-emergency.sh
Harald Hoyer 414eba
index 63311c2..548f64b 100755
Harald Hoyer 414eba
--- a/modules.d/98dracut-systemd/dracut-emergency.sh
Harald Hoyer 414eba
+++ b/modules.d/98dracut-systemd/dracut-emergency.sh
Harald Hoyer 414eba
@@ -11,7 +11,7 @@ source_conf /etc/conf.d
Harald Hoyer 414eba
 type plymouth >/dev/null 2>&1 && plymouth quit
Harald Hoyer 414eba
 
Harald Hoyer 414eba
 export _rdshell_name="dracut" action="Boot" hook="emergency"
Harald Hoyer 414eba
-
Harald Hoyer 414eba
+_emergency_action=$(getarg rd.emergency)
Harald Hoyer 414eba
 
Harald Hoyer 414eba
 if getargbool 1 rd.shell -d -y rdshell || getarg rd.break -d rdbreak; then
Harald Hoyer 414eba
     source_hook "$hook"
Harald Hoyer 414eba
@@ -32,9 +32,18 @@ else
Harald Hoyer 414eba
     export hook="shutdown-emergency"
Harald Hoyer 414eba
     warn "$action has failed. To debug this issue add \"rd.shell rd.debug\" to the kernel command line."
Harald Hoyer 414eba
     source_hook "$hook"
Harald Hoyer 414eba
-    exit 1
Harald Hoyer 414eba
+    [ -z "$_emergency_action" ] && _emergency_action=halt
Harald Hoyer 414eba
 fi
Harald Hoyer 414eba
 
Harald Hoyer 414eba
 /bin/rm -f -- /.console_lock
Harald Hoyer 414eba
 
Harald Hoyer 414eba
+case "$_emergency_action" in
Harald Hoyer 414eba
+    reboot)
Harald Hoyer 414eba
+        reboot || exit 1;;
Harald Hoyer 414eba
+    poweroff)
Harald Hoyer 414eba
+        poweroff || exit 1;;
Harald Hoyer 414eba
+    halt)
Harald Hoyer 414eba
+        halt || exit 1;;
Harald Hoyer 414eba
+esac
Harald Hoyer 414eba
+
Harald Hoyer 414eba
 exit 0
Harald Hoyer 414eba
diff --git a/modules.d/99base/dracut-lib.sh b/modules.d/99base/dracut-lib.sh
Harald Hoyer 414eba
index 94e4614..060b3fe 100755
Harald Hoyer 414eba
--- a/modules.d/99base/dracut-lib.sh
Harald Hoyer 414eba
+++ b/modules.d/99base/dracut-lib.sh
Harald Hoyer 414eba
@@ -1111,6 +1111,8 @@ emergency_shell()
Harald Hoyer 414eba
     local _ctty
Harald Hoyer 414eba
     set +e
Harald Hoyer 414eba
     local _rdshell_name="dracut" action="Boot" hook="emergency"
Harald Hoyer 414eba
+    local _emergency_action
Harald Hoyer 414eba
+
Harald Hoyer 414eba
     if [ "$1" = "-n" ]; then
Harald Hoyer 414eba
         _rdshell_name=$2
Harald Hoyer 414eba
         shift 2
Harald Hoyer 414eba
@@ -1129,20 +1131,26 @@ emergency_shell()
Harald Hoyer 414eba
     source_hook "$hook"
Harald Hoyer 414eba
     echo
Harald Hoyer 414eba
 
Harald Hoyer 414eba
+    _emergency_action=$(getarg rd.emergency)
Harald Hoyer 414eba
+    [ -z "$_emergency_action" ] \
Harald Hoyer 414eba
+        && [ -e /run/initramfs/.die ] \
Harald Hoyer 414eba
+        && _emergency_action=halt
Harald Hoyer 414eba
+
Harald Hoyer 414eba
     if getargbool 1 rd.shell -d -y rdshell || getarg rd.break -d rdbreak; then
Harald Hoyer 414eba
         _emergency_shell $_rdshell_name
Harald Hoyer 414eba
     else
Harald Hoyer 414eba
         warn "$action has failed. To debug this issue add \"rd.shell rd.debug\" to the kernel command line."
Harald Hoyer 414eba
-        # cause a kernel panic
Harald Hoyer 414eba
-        exit 1
Harald Hoyer 414eba
+        [ -z "$_emergency_action" ] && _emergency_action=halt
Harald Hoyer 414eba
     fi
Harald Hoyer 414eba
 
Harald Hoyer 414eba
-    if [ -e /run/initramfs/.die ]; then
Harald Hoyer 414eba
-        if [ -n "$DRACUT_SYSTEMD" ]; then
Harald Hoyer 414eba
-            systemctl --no-block --force halt
Harald Hoyer 414eba
-        fi
Harald Hoyer 414eba
-        exit 1
Harald Hoyer 414eba
-    fi
Harald Hoyer 414eba
+    case "$_emergency_action" in
Harald Hoyer 414eba
+        reboot)
Harald Hoyer 414eba
+            reboot || exit 1;;
Harald Hoyer 414eba
+        poweroff)
Harald Hoyer 414eba
+            poweroff || exit 1;;
Harald Hoyer 414eba
+        halt)
Harald Hoyer 414eba
+            halt || exit 1;;
Harald Hoyer 414eba
+    esac
Harald Hoyer 414eba
 }
Harald Hoyer 414eba
 
Harald Hoyer 414eba
 # Retain the values of these variables but ensure that they are unexported