Blame SOURCES/0448-add-rd.emergency-reboot-poweroff-halt.patch

18971c
From cd6679c71665a53e2a55a204e7ea64b4a6d14030 Mon Sep 17 00:00:00 2001
18971c
From: Harald Hoyer <harald@redhat.com>
18971c
Date: Fri, 22 Jul 2016 13:32:47 +0200
18971c
Subject: [PATCH] add rd.emergency=[reboot|poweroff|halt]
18971c
18971c
specifies what action to execute in case of a critical failure
18971c
18971c
(cherry picked from commit c45e856a659a37537c107f7ef3e680abf60a96a5)
18971c
18971c
https://bugzilla.redhat.com/show_bug.cgi?id=1359144
18971c
---
18971c
 dracut.cmdline.7.asc                    |  3 +++
18971c
 modules.d/98systemd/dracut-emergency.sh | 12 +++++++++++-
18971c
 modules.d/99base/dracut-lib.sh          | 24 ++++++++++++++++--------
18971c
 3 files changed, 30 insertions(+), 9 deletions(-)
18971c
18971c
diff --git a/dracut.cmdline.7.asc b/dracut.cmdline.7.asc
18971c
index 1cf962e6..1fb4f746 100644
18971c
--- a/dracut.cmdline.7.asc
18971c
+++ b/dracut.cmdline.7.asc
18971c
@@ -108,6 +108,9 @@ resume=UUID=3f5ad593-4546-4a94-a374-bcfb68aa11f7
18971c
 
18971c
 Misc
18971c
 ~~~~
18971c
+**rd.emergency=**__[reboot|poweroff|halt]__::
18971c
+    specify, what action to execute in case of a critical failure.
18971c
+
18971c
 **rd.driver.blacklist=**__<drivername>__[,__<drivername>__,...]::
18971c
     do not load kernel module <drivername>. This parameter can be specified
18971c
     multiple times.
18971c
diff --git a/modules.d/98systemd/dracut-emergency.sh b/modules.d/98systemd/dracut-emergency.sh
18971c
index 5771dc5e..b3e8d087 100755
18971c
--- a/modules.d/98systemd/dracut-emergency.sh
18971c
+++ b/modules.d/98systemd/dracut-emergency.sh
18971c
@@ -16,6 +16,7 @@ export _rdshell_name="dracut" action="Boot" hook="emergency"
18971c
 
18971c
 source_hook "$hook"
18971c
 
18971c
+_emergency_action=$(getarg rd.emergency)
18971c
 
18971c
 if getargbool 1 rd.shell -d -y rdshell || getarg rd.break -d rdbreak; then
18971c
     echo
18971c
@@ -33,9 +34,18 @@ if getargbool 1 rd.shell -d -y rdshell || getarg rd.break -d rdbreak; then
18971c
     exec sh -i -l
18971c
 else
18971c
     warn "$action has failed. To debug this issue add \"rd.shell rd.debug\" to the kernel command line."
18971c
-    exit 1
18971c
+    [ -z "$_emergency_action" ] && _emergency_action=halt
18971c
 fi
18971c
 
18971c
 /bin/rm -f -- /.console_lock
18971c
 
18971c
+case "$_emergency_action" in
18971c
+    reboot)
18971c
+        reboot || exit 1;;
18971c
+    poweroff)
18971c
+        poweroff || exit 1;;
18971c
+    halt)
18971c
+        halt || exit 1;;
18971c
+esac
18971c
+
18971c
 exit 0
18971c
diff --git a/modules.d/99base/dracut-lib.sh b/modules.d/99base/dracut-lib.sh
18971c
index 16bc74d4..10d9cbc5 100755
18971c
--- a/modules.d/99base/dracut-lib.sh
18971c
+++ b/modules.d/99base/dracut-lib.sh
18971c
@@ -1068,6 +1068,8 @@ emergency_shell()
18971c
     local _ctty
18971c
     set +e
18971c
     local _rdshell_name="dracut" action="Boot" hook="emergency"
18971c
+    local _emergency_action
18971c
+
18971c
     if [ "$1" = "-n" ]; then
18971c
         _rdshell_name=$2
18971c
         shift 2
18971c
@@ -1086,20 +1088,26 @@ emergency_shell()
18971c
     source_hook "$hook"
18971c
     echo
18971c
 
18971c
+    _emergency_action=$(getarg rd.emergency)
18971c
+    [ -z "$_emergency_action" ] \
18971c
+        && [ -e /run/initramfs/.die ] \
18971c
+        && _emergency_action=halt
18971c
+
18971c
     if getargbool 1 rd.shell -d -y rdshell || getarg rd.break -d rdbreak; then
18971c
         _emergency_shell $_rdshell_name
18971c
     else
18971c
         warn "$action has failed. To debug this issue add \"rd.shell rd.debug\" to the kernel command line."
18971c
-        # cause a kernel panic
18971c
-        exit 1
18971c
+        [ -z "$_emergency_action" ] && _emergency_action=halt
18971c
     fi
18971c
 
18971c
-    if [ -e /run/initramfs/.die ]; then
18971c
-        if [ -n "$DRACUT_SYSTEMD" ]; then
18971c
-            systemctl --no-block --force halt
18971c
-        fi
18971c
-        exit 1
18971c
-    fi
18971c
+    case "$_emergency_action" in
18971c
+        reboot)
18971c
+            reboot || exit 1;;
18971c
+        poweroff)
18971c
+            poweroff || exit 1;;
18971c
+        halt)
18971c
+            halt || exit 1;;
18971c
+    esac
18971c
 }
18971c
 
18971c
 action_on_fail()