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

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