summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Hutchings <ben@decadent.org.uk>2018-07-27 16:24:55 +0800
committerBen Hutchings <benh@debian.org>2020-09-06 23:23:20 +0100
commit6300aa109a7c8651a5e0c4d84ca10b363ddd5387 (patch)
treeb033f1fbeaff15577ba2439243ee5fed427b4b4f
parent4309c3bcd97acdb17e250c56811faa9cfb4091fd (diff)
Change "panic" parameter handling to work more like the kernel
Negative timeout values are treated by the kernel as "reboot immediately" and 0 is treated as "wait forever". Emulate this behaviour in the panic() function. Treat invalid (non-numeric) values the same as 0, which seems to match what the kernel does. Previously we would ignore them completely and open a shell as normal. Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
-rwxr-xr-xinit5
-rw-r--r--scripts/functions27
2 files changed, 23 insertions, 9 deletions
diff --git a/init b/init
index 43f6828..3ad5579 100755
--- a/init
+++ b/init
@@ -135,11 +135,6 @@ for x in $(cat /proc/cmdline); do
;;
panic=*)
panic="${x#panic=}"
- case ${panic} in
- *[![:digit:].]*)
- panic=
- ;;
- esac
;;
ro)
readonly=y
diff --git a/scripts/functions b/scripts/functions
index d8fb0ca..eccad66 100644
--- a/scripts/functions
+++ b/scripts/functions
@@ -42,11 +42,30 @@ panic()
fi
echo "$@"
- # Disallow console access
+
+ # The panic= parameter implies we should disallow console access
if [ -n "${panic?}" ]; then
- echo "Rebooting automatically due to panic= boot argument"
- sleep "${panic}"
- reboot -f
+ delay=
+ case "${panic?}" in
+ -*[![:digit:].]*) # invalid: wait forever
+ ;;
+ -*) # timeout < 0: reboot immediately
+ delay=0
+ ;;
+ 0 | *[![:digit:].]*) # timeout = 0 or invalid: wait forever
+ ;;
+ *) # timeout > 0: seconds before rebooting
+ delay="${panic}"
+ ;;
+ esac
+ if [ -n "${delay}" ]; then
+ echo "Rebooting automatically due to panic= boot argument"
+ sleep "${delay}"
+ reboot -f
+ else
+ echo "Halting automatically due to panic= boot argument"
+ halt -f
+ fi
exit # in case reboot fails, force kernel panic
fi