Blame 0016-Let-user-specify-the-action-after-fail.patch

Harald Hoyer ab11ed
From 9d787df19674937e8c07bd295b5d282a63829209 Mon Sep 17 00:00:00 2001
Harald Hoyer ab11ed
From: Baoquan He <bhe@redhat.com>
Harald Hoyer ab11ed
Date: Fri, 29 Mar 2013 18:36:16 +0800
Harald Hoyer ab11ed
Subject: [PATCH] Let user specify the action after fail
Harald Hoyer ab11ed
Harald Hoyer ab11ed
Currently the default action is emergency_shell when failure happened
Harald Hoyer ab11ed
during system boot. In kdump, this default may not be expected. E.g,
Harald Hoyer ab11ed
if dump target is not rootfs, it does not matter if mount root failed.
Harald Hoyer ab11ed
Adding an action which allow dracut always go ahead though failure
Harald Hoyer ab11ed
happens is needed by kdump.
Harald Hoyer ab11ed
Harald Hoyer ab11ed
So here add a function action_on_fail() and cmdline parameter
Harald Hoyer ab11ed
action_on_fail=<shell | continue>. Use action_to_fail() to replace
Harald Hoyer ab11ed
emergency_shell which was called after failure. By $(getarg action_on_fail=),
Harald Hoyer ab11ed
decide to drop into shell, or to leave away the failure and go ahead.
Harald Hoyer ab11ed
Harald Hoyer ab11ed
v3->v4:
Harald Hoyer ab11ed
add handling of selinux policy loaded failure, and change code format to
Harald Hoyer ab11ed
be consitent
Harald Hoyer ab11ed
Harald Hoyer ab11ed
Signed-off-by: Baoquan He <bhe@redhat.com>
Harald Hoyer ab11ed
Harald Hoyer ab11ed
[Edited by harald@redhat.com]
Harald Hoyer ab11ed
---
Harald Hoyer ab11ed
 dracut.cmdline.7.asc                      |  4 ++++
Harald Hoyer ab11ed
 modules.d/95rootfs-block/mount-root.sh    |  2 +-
Harald Hoyer ab11ed
 modules.d/98selinux/selinux-loadpolicy.sh |  6 ++----
Harald Hoyer ab11ed
 modules.d/98systemd/dracut-initqueue.sh   |  2 +-
Harald Hoyer ab11ed
 modules.d/98systemd/dracut-mount.sh       |  2 +-
Harald Hoyer ab11ed
 modules.d/98usrmount/mount-usr.sh         |  4 ++--
Harald Hoyer ab11ed
 modules.d/99base/dracut-lib.sh            | 22 ++++++++++++++++++++++
Harald Hoyer ab11ed
 modules.d/99base/init.sh                  | 12 ++++++------
Harald Hoyer ab11ed
 8 files changed, 39 insertions(+), 15 deletions(-)
Harald Hoyer ab11ed
Harald Hoyer ab11ed
diff --git a/dracut.cmdline.7.asc b/dracut.cmdline.7.asc
Harald Hoyer ab11ed
index f1457d5..4626279 100644
Harald Hoyer ab11ed
--- a/dracut.cmdline.7.asc
Harald Hoyer ab11ed
+++ b/dracut.cmdline.7.asc
Harald Hoyer ab11ed
@@ -121,6 +121,10 @@ Misc
Harald Hoyer ab11ed
    specify the controlling terminal for the console.
Harald Hoyer ab11ed
    This is useful, if you have multiple "console=" arguments.
Harald Hoyer ab11ed
 
Harald Hoyer ab11ed
+**action_on_fail=**_{shell|continue}_::
Harald Hoyer ab11ed
+   Specify the action after failure. By default it's emergency_shell.
Harald Hoyer ab11ed
+   'continue' means: ignore the current failure and go ahead.
Harald Hoyer ab11ed
+
Harald Hoyer ab11ed
 [[dracutkerneldebug]]
Harald Hoyer ab11ed
 Debug
Harald Hoyer ab11ed
 ~~~~~
Harald Hoyer ab11ed
diff --git a/modules.d/95rootfs-block/mount-root.sh b/modules.d/95rootfs-block/mount-root.sh
Harald Hoyer ab11ed
index c7626c3..6ed35c1 100755
Harald Hoyer ab11ed
--- a/modules.d/95rootfs-block/mount-root.sh
Harald Hoyer ab11ed
+++ b/modules.d/95rootfs-block/mount-root.sh
Harald Hoyer ab11ed
@@ -68,7 +68,7 @@ mount_root() {
Harald Hoyer ab11ed
                 warn "*** Warning -- the system did not shut down cleanly. "
Harald Hoyer ab11ed
                 warn "*** Dropping you to a shell; the system will continue"
Harald Hoyer ab11ed
                 warn "*** when you leave the shell."
Harald Hoyer ab11ed
-                emergency_shell
Harald Hoyer ab11ed
+                action_on_fail
Harald Hoyer ab11ed
             fi
Harald Hoyer ab11ed
             fsckoptions="$AUTOFSCK_OPT $fsckoptions"
Harald Hoyer ab11ed
         fi
Harald Hoyer ab11ed
diff --git a/modules.d/98selinux/selinux-loadpolicy.sh b/modules.d/98selinux/selinux-loadpolicy.sh
Harald Hoyer ab11ed
index d6e24d6..7526265 100755
Harald Hoyer ab11ed
--- a/modules.d/98selinux/selinux-loadpolicy.sh
Harald Hoyer ab11ed
+++ b/modules.d/98selinux/selinux-loadpolicy.sh
Harald Hoyer ab11ed
@@ -52,16 +52,14 @@ rd_load_policy()
Harald Hoyer ab11ed
         if [ $ret -eq 3 -o $permissive -eq 0 ]; then
Harald Hoyer ab11ed
             warn "Machine in enforcing mode."
Harald Hoyer ab11ed
             warn "Not continuing"
Harald Hoyer ab11ed
-            emergency_shell -n selinux
Harald Hoyer ab11ed
-            exit 1
Harald Hoyer ab11ed
+            action_on_fail -n selinux || exit 1
Harald Hoyer ab11ed
         fi
Harald Hoyer ab11ed
         return 0
Harald Hoyer ab11ed
     elif [ $permissive -eq 0 -a "$SELINUX" != "disabled" ]; then
Harald Hoyer ab11ed
         warn "Machine in enforcing mode and cannot execute load_policy."
Harald Hoyer ab11ed
         warn "To disable selinux, add selinux=0 to the kernel command line."
Harald Hoyer ab11ed
         warn "Not continuing"
Harald Hoyer ab11ed
-        emergency_shell -n selinux
Harald Hoyer ab11ed
-        exit 1
Harald Hoyer ab11ed
+        action_on_fail -n selinux || exit 1
Harald Hoyer ab11ed
     fi
Harald Hoyer ab11ed
 }
Harald Hoyer ab11ed
 
Harald Hoyer ab11ed
diff --git a/modules.d/98systemd/dracut-initqueue.sh b/modules.d/98systemd/dracut-initqueue.sh
Harald Hoyer ab11ed
index c6fab30..2c71bf4 100755
Harald Hoyer ab11ed
--- a/modules.d/98systemd/dracut-initqueue.sh
Harald Hoyer ab11ed
+++ b/modules.d/98systemd/dracut-initqueue.sh
Harald Hoyer ab11ed
@@ -62,7 +62,7 @@ while :; do
Harald Hoyer ab11ed
     fi
Harald Hoyer ab11ed
 
Harald Hoyer ab11ed
     main_loop=$(($main_loop+1))
Harald Hoyer ab11ed
-    [ $main_loop -gt $RDRETRY ] && emergency_shell "Could not boot."
Harald Hoyer ab11ed
+    [ $main_loop -gt $RDRETRY ] && action_on_fail "Could not boot." && break
Harald Hoyer ab11ed
 done
Harald Hoyer ab11ed
 
Harald Hoyer ab11ed
 unset job
Harald Hoyer ab11ed
diff --git a/modules.d/98systemd/dracut-mount.sh b/modules.d/98systemd/dracut-mount.sh
Harald Hoyer ab11ed
index 5f3d9f0..ae01512 100755
Harald Hoyer ab11ed
--- a/modules.d/98systemd/dracut-mount.sh
Harald Hoyer ab11ed
+++ b/modules.d/98systemd/dracut-mount.sh
Harald Hoyer ab11ed
@@ -31,7 +31,7 @@ while :; do
Harald Hoyer ab11ed
     done
Harald Hoyer ab11ed
 
Harald Hoyer ab11ed
     i=$(($i+1))
Harald Hoyer ab11ed
-    [ $i -gt 20 ] && emergency_shell "Can't mount root filesystem"
Harald Hoyer ab11ed
+    [ $i -gt 20 ] && action_on_fail "Can't mount root filesystem" && break
Harald Hoyer ab11ed
 done
Harald Hoyer ab11ed
 
Harald Hoyer ab11ed
 export -p > /dracut-state.sh
Harald Hoyer ab11ed
diff --git a/modules.d/98usrmount/mount-usr.sh b/modules.d/98usrmount/mount-usr.sh
Harald Hoyer ab11ed
index 5aaefbc..a4a66ae 100755
Harald Hoyer ab11ed
--- a/modules.d/98usrmount/mount-usr.sh
Harald Hoyer ab11ed
+++ b/modules.d/98usrmount/mount-usr.sh
Harald Hoyer ab11ed
@@ -42,7 +42,7 @@ fsck_usr()
Harald Hoyer ab11ed
             warn "*** Warning -- the system did not shut down cleanly. "
Harald Hoyer ab11ed
             warn "*** Dropping you to a shell; the system will continue"
Harald Hoyer ab11ed
             warn "*** when you leave the shell."
Harald Hoyer ab11ed
-            emergency_shell
Harald Hoyer ab11ed
+            action_on_fail
Harald Hoyer ab11ed
         fi
Harald Hoyer ab11ed
         _fsckoptions="$AUTOFSCK_OPT $_fsckoptions"
Harald Hoyer ab11ed
     fi
Harald Hoyer ab11ed
@@ -105,7 +105,7 @@ mount_usr()
Harald Hoyer ab11ed
             warn "Mounting /usr to $NEWROOT/usr failed"
Harald Hoyer ab11ed
             warn "*** Dropping you to a shell; the system will continue"
Harald Hoyer ab11ed
             warn "*** when you leave the shell."
Harald Hoyer ab11ed
-            emergency_shell
Harald Hoyer ab11ed
+            action_on_fail
Harald Hoyer ab11ed
         fi
Harald Hoyer ab11ed
     fi
Harald Hoyer ab11ed
 }
Harald Hoyer ab11ed
diff --git a/modules.d/99base/dracut-lib.sh b/modules.d/99base/dracut-lib.sh
Harald Hoyer ab11ed
index f2b16d3..1defb6f 100755
Harald Hoyer ab11ed
--- a/modules.d/99base/dracut-lib.sh
Harald Hoyer ab11ed
+++ b/modules.d/99base/dracut-lib.sh
Harald Hoyer ab11ed
@@ -994,6 +994,28 @@ emergency_shell()
Harald Hoyer ab11ed
     [ -e /run/initramfs/.die ] && exit 1
Harald Hoyer ab11ed
 }
Harald Hoyer ab11ed
 
Harald Hoyer ab11ed
+action_on_fail()
Harald Hoyer ab11ed
+{
Harald Hoyer ab11ed
+    local _action=$(getarg action_on_fail=)
Harald Hoyer ab11ed
+    case "$_action" in
Harald Hoyer ab11ed
+        continue)
Harald Hoyer ab11ed
+            [ "$1" = "-n" ] && shift 2
Harald Hoyer ab11ed
+            [ "$1" = "--shutdown" ] && shift 2
Harald Hoyer ab11ed
+            warn "$*"
Harald Hoyer ab11ed
+            warn "Not dropping to emergency shell, because 'action_on_fail=continue' was set on the kernel command line."
Harald Hoyer ab11ed
+            return 0
Harald Hoyer ab11ed
+            ;;
Harald Hoyer ab11ed
+        shell)
Harald Hoyer ab11ed
+            emergency_shell $@
Harald Hoyer ab11ed
+            return 1
Harald Hoyer ab11ed
+            ;;
Harald Hoyer ab11ed
+        *)
Harald Hoyer ab11ed
+            emergency_shell $@
Harald Hoyer ab11ed
+            return 1
Harald Hoyer ab11ed
+            ;;
Harald Hoyer ab11ed
+    esac
Harald Hoyer ab11ed
+}
Harald Hoyer ab11ed
+
Harald Hoyer ab11ed
 # Retain the values of these variables but ensure that they are unexported
Harald Hoyer ab11ed
 # This is a POSIX-compliant equivalent of bash's "export -n"
Harald Hoyer ab11ed
 export_n()
Harald Hoyer ab11ed
diff --git a/modules.d/99base/init.sh b/modules.d/99base/init.sh
Harald Hoyer ab11ed
index 410201a..880a2c0 100755
Harald Hoyer ab11ed
--- a/modules.d/99base/init.sh
Harald Hoyer ab11ed
+++ b/modules.d/99base/init.sh
Harald Hoyer ab11ed
@@ -79,7 +79,7 @@ if ! ismounted /run; then
Harald Hoyer ab11ed
     rm -fr /newrun
Harald Hoyer ab11ed
 fi
Harald Hoyer ab11ed
 
Harald Hoyer ab11ed
-trap "emergency_shell Signal caught!" 0
Harald Hoyer ab11ed
+trap "action_on_fail Signal caught!" 0
Harald Hoyer ab11ed
 
Harald Hoyer ab11ed
 [ -d /run/initramfs ] || mkdir -p -m 0755 /run/initramfs
Harald Hoyer ab11ed
 [ -d /run/log ] || mkdir -p -m 0755 /run/log
Harald Hoyer ab11ed
@@ -199,7 +199,7 @@ while :; do
Harald Hoyer ab11ed
 
Harald Hoyer ab11ed
     main_loop=$(($main_loop+1))
Harald Hoyer ab11ed
     [ $main_loop -gt $RDRETRY ] \
Harald Hoyer ab11ed
-        && { flock -s 9 ; emergency_shell "Could not boot."; } 9>/.console_lock
Harald Hoyer ab11ed
+        && { flock -s 9 ; action_on_fail "Could not boot." && break; } 9>/.console_lock
Harald Hoyer ab11ed
 done
Harald Hoyer ab11ed
 unset job
Harald Hoyer ab11ed
 unset queuetriggered
Harald Hoyer ab11ed
@@ -234,7 +234,7 @@ while :; do
Harald Hoyer ab11ed
 
Harald Hoyer ab11ed
     i=$(($i+1))
Harald Hoyer ab11ed
     [ $i -gt 20 ] \
Harald Hoyer ab11ed
-        && { flock -s 9 ; emergency_shell "Can't mount root filesystem"; } 9>/.console_lock
Harald Hoyer ab11ed
+        && { flock -s 9 ; action_on_fail "Can't mount root filesystem" && break; } 9>/.console_lock
Harald Hoyer ab11ed
 done
Harald Hoyer ab11ed
 
Harald Hoyer ab11ed
 {
Harald Hoyer ab11ed
@@ -268,7 +268,7 @@ done
Harald Hoyer ab11ed
 [ "$INIT" ] || {
Harald Hoyer ab11ed
     echo "Cannot find init!"
Harald Hoyer ab11ed
     echo "Please check to make sure you passed a valid root filesystem!"
Harald Hoyer ab11ed
-    emergency_shell
Harald Hoyer ab11ed
+    action_on_fail
Harald Hoyer ab11ed
 }
Harald Hoyer ab11ed
 
Harald Hoyer ab11ed
 if [ $UDEVVERSION -lt 168 ]; then
Harald Hoyer ab11ed
@@ -370,13 +370,13 @@ if [ -f /etc/capsdrop ]; then
Harald Hoyer ab11ed
 	warn "Command:"
Harald Hoyer ab11ed
 	warn capsh --drop=$CAPS_INIT_DROP -- -c exec switch_root "$NEWROOT" "$INIT" $initargs
Harald Hoyer ab11ed
 	warn "failed."
Harald Hoyer ab11ed
-	emergency_shell
Harald Hoyer ab11ed
+	action_on_fail
Harald Hoyer ab11ed
     }
Harald Hoyer ab11ed
 else
Harald Hoyer ab11ed
     unset RD_DEBUG
Harald Hoyer ab11ed
     exec $SWITCH_ROOT "$NEWROOT" "$INIT" $initargs || {
Harald Hoyer ab11ed
 	warn "Something went very badly wrong in the initramfs.  Please "
Harald Hoyer ab11ed
 	warn "file a bug against dracut."
Harald Hoyer ab11ed
-	emergency_shell
Harald Hoyer ab11ed
+	action_on_fail
Harald Hoyer ab11ed
     }
Harald Hoyer ab11ed
 fi