diff mbox

[mkinitcpio] init: introduce a non-interactive mode (rd.noninteractive)

Message ID 20170227092026.29134-1-martin.peres@free.fr
State New
Headers show

Commit Message

Martin Peres Feb. 27, 2017, 9:20 a.m. UTC
CI systems compile and boot on kernels that are sometimes broken and
fail to find the root device.

This patch adds a new parameter (rd.noninteractive) that prevents
starting an interactive shell and reboots the machine 2 seconds after
warning the user about the issue.

This allows me to test the kernel faster than would be possible using
external watchdogs which would require at least 2 minutes before
kicking in.
---
 init_functions          | 16 ++++++++++++++++
 man/mkinitcpio.8.txt    |  3 +++
 test/test_parse_cmdline |  2 ++
 3 files changed, 21 insertions(+)

Comments

Martin Peres March 10, 2017, 12:24 p.m. UTC | #1
On 27/02/17 11:20, Martin Peres wrote:
> CI systems compile and boot on kernels that are sometimes broken and
> fail to find the root device.
>
> This patch adds a new parameter (rd.noninteractive) that prevents
> starting an interactive shell and reboots the machine 2 seconds after
> warning the user about the issue.
>
> This allows me to test the kernel faster than would be possible using
> external watchdogs which would require at least 2 minutes before
> kicking in.

Gentle ping :)
diff mbox

Patch

diff --git a/init_functions b/init_functions
index d5a584e..7287086 100644
--- a/init_functions
+++ b/init_functions
@@ -47,6 +47,19 @@  poll_device() {
 }
 
 launch_interactive_shell() {
+    if [ -n "$rd_noninteractive" ]; then
+        printf '%s\n' \
+                "************** REBOOT REQUIRED **************" \
+                "*                                           *" \
+                "*      running in non-interactive mode      *" \
+                "*                     -                     *" \
+                "*   automatically restarting in 2 seconds   *" \
+                "*                                           *" \
+                "*********************************************"
+        sleep 2
+        reboot -f
+    fi
+
     export PS1='[rootfs \W]\$ '
 
     # explicitly redirect to /dev/console in case we're logging. note that
@@ -174,6 +187,9 @@  parse_cmdline_item() {
                 rd_logmask=$(( _rdlog_kmsg | _rdlog_cons ))
             fi
             ;;
+        rd.noninteractive)
+            rd_noninteractive=y
+            ;;
         [![:alpha:]_]*|[[:alpha:]_]*[![:alnum:]_]*)
             # invalid shell variable, ignore it
             ;;
diff --git a/man/mkinitcpio.8.txt b/man/mkinitcpio.8.txt
index 5c3118e..d9410dc 100644
--- a/man/mkinitcpio.8.txt
+++ b/man/mkinitcpio.8.txt
@@ -292,6 +292,9 @@  the kernel command line:
 	*all*;;
 		Writes output to all known log targets.
 
+*rd.noninteractive*::
+	If specified, reboot the machine instead of starting an interactive shell.
+
 These are only the variables that the core of mkinitcpio honor. Additional
 hooks may look for other environment variables and should be documented by the
 help output for the hook.
diff --git a/test/test_parse_cmdline b/test/test_parse_cmdline
index ff855e4..9249962 100755
--- a/test/test_parse_cmdline
+++ b/test/test_parse_cmdline
@@ -217,6 +217,8 @@  test_parse 'rd.log=kmsg' \
   'rd_logmask' '2'
 test_parse 'rd.log=file' \
   'rd_logmask' '1'
+test_parse 'rd.noninteractive' \
+  'rd_noninteractive' 'y'
 
 # a mix of stuff
 test_parse 'foo=bar bareword bar="ba az"' \