A patch from Matt Kraai that adds a new 'shutdown' action to busybox init. Now
you can specify an arbitrary behavior for 'ctrlaltdel' without that behavior
needing to be a reboot.
diff --git a/Changelog b/Changelog
index 19acbbd..42dcfec 100644
--- a/Changelog
+++ b/Changelog
@@ -1,7 +1,12 @@
0.51pre
* Erik Andersen -- added env applet
* Erik Andersen -- Split utility.c into libbb
- * <fixme>
+ * Andreas Neuhaus <andy@fasta.fh-dortmund.de> -- fix for merging
+ kernel command line environment variables into child environment
+ for init.c
+ * Matt Kraai -- Added a new 'shutdown' action to busybox init. Now
+ you can specify arbitrary behavior for 'ctrlaltdel' without that
+ behavior needing to be a reboot.
-Erik Andersen, not yet released
diff --git a/applets/usage.h b/applets/usage.h
index 1ee2ab3..aa7f0af 100644
--- a/applets/usage.h
+++ b/applets/usage.h
@@ -663,10 +663,15 @@
"\n" \
" ::sysinit:/etc/init.d/rcS\n" \
" ::askfirst:/bin/sh\n" \
+" ::ctrlaltdel:/sbin/reboot\n" \
+" ::shutdown:/sbin/swapoff -a\n" \
+" ::shutdown:/bin/umount -a -r\n" \
"\n" \
"if it detects that /dev/console is _not_ a serial console, it will also run:\n" \
"\n" \
" tty2::askfirst:/bin/sh\n" \
+" tty3::askfirst:/bin/sh\n" \
+" tty4::askfirst:/bin/sh\n" \
"\n" \
"If you choose to use an /etc/inittab file, the inittab entry format is as follows:\n" \
"\n" \
@@ -692,7 +697,7 @@
" <action>: \n" \
"\n" \
" Valid actions include: sysinit, respawn, askfirst, wait, \n" \
-" once, and ctrlaltdel.\n" \
+" once, ctrlaltdel, and shutdown.\n" \
"\n" \
" The available actions can be classified into two groups: actions\n" \
" that are run only once, and actions that are re-run when the specified\n" \
@@ -706,9 +711,12 @@
" 'wait' actions, like 'sysinit' actions, cause init to wait until\n" \
" the specified task completes. 'once' actions are asyncronous,\n" \
" therefore, init does not wait for them to complete. 'ctrlaltdel'\n" \
-" actions are run immediately before init causes the system to reboot\n" \
-" (unmounting filesystems with a 'ctrlaltdel' action is a very good\n" \
-" idea).\n" \
+" actions are run when the system detects that someone on the system\n" \
+" console has pressed the CTRL-ALT-DEL key combination. Typically one\n" \
+" wants to run 'reboot' at this point to cause the system to reboot.\n" \
+" Finally the 'shutdown' action specifies the actions to taken when\n" \
+" init is told to reboot. Unmounting filesystems and disabling swap\n" \
+" is a very good here\n" \
"\n" \
" Run repeatedly actions:\n" \
"\n" \
@@ -759,8 +767,9 @@
" #::respawn:/sbin/getty 57600 ttyS2\n" \
" \n" \
" # Stuff to do before rebooting\n" \
-" ::ctrlaltdel:/bin/umount -a -r\n" \
-" ::ctrlaltdel:/sbin/swapoff -a\n"
+" ::ctrlaltdel:/sbin/reboot\n" \
+" ::shutdown:/bin/umount -a -r\n" \
+" ::shutdown:/sbin/swapoff -a\n"
#define insmod_trivial_usage \
"[OPTION]... MODULE [symbol=value]..."
diff --git a/docs/busybox.pod b/docs/busybox.pod
index 644abc3..4294448 100644
--- a/docs/busybox.pod
+++ b/docs/busybox.pod
@@ -906,10 +906,15 @@
::sysinit:/etc/init.d/rcS
::askfirst:/bin/sh
+ ::ctrlaltdel:/sbin/reboot
+ ::shutdown:/sbin/swapoff -a
+ ::shutdown:/bin/umount -a -r
if it detects that /dev/console is _not_ a serial console, it will also run:
tty2::askfirst:/bin/sh
+ tty3::askfirst:/bin/sh
+ tty4::askfirst:/bin/sh
If you choose to use an /etc/inittab file, the inittab entry format is as follows:
@@ -935,7 +940,7 @@
<action>:
Valid actions include: sysinit, respawn, askfirst, wait,
- once, and ctrlaltdel.
+ once, ctrlaltdel, and shutdown.
The available actions can be classified into two groups: actions
that are run only once, and actions that are re-run when the specified
@@ -949,9 +954,12 @@
'wait' actions, like 'sysinit' actions, cause init to wait until
the specified task completes. 'once' actions are asyncronous,
therefore, init does not wait for them to complete. 'ctrlaltdel'
- actions are run immediately before init causes the system to reboot
- (unmounting filesystems with a 'ctrlaltdel' action is a very good
- idea).
+ actions are run when the system detects that someone on the system
+ console has pressed the CTRL-ALT-DEL key combination. Typically one
+ wants to run 'reboot' at this point to cause the system to reboot.
+ Finally the 'shutdown' action specifies the actions to taken when
+ init is told to reboot. Unmounting filesystems and disabling swap
+ is a very good here.
Run repeatedly actions:
@@ -984,10 +992,9 @@
tty4::respawn:/sbin/getty 38400 tty5
tty5::respawn:/sbin/getty 38400 tty6
-
-
- ::ctrlaltdel:/bin/umount -a -r
- ::ctrlaltdel:/sbin/swapoff -a
+ ::ctrlaltdel:/sbin/reboot
+ ::shutdown:/bin/umount -a -r
+ ::shutdown:/sbin/swapoff -a
-------------------------------
@@ -2476,4 +2483,4 @@
=cut
-# $Id: busybox.pod,v 1.92 2001/03/15 21:20:25 markw Exp $
+# $Id: busybox.pod,v 1.93 2001/04/03 18:01:51 andersen Exp $
diff --git a/include/usage.h b/include/usage.h
index 1ee2ab3..aa7f0af 100644
--- a/include/usage.h
+++ b/include/usage.h
@@ -663,10 +663,15 @@
"\n" \
" ::sysinit:/etc/init.d/rcS\n" \
" ::askfirst:/bin/sh\n" \
+" ::ctrlaltdel:/sbin/reboot\n" \
+" ::shutdown:/sbin/swapoff -a\n" \
+" ::shutdown:/bin/umount -a -r\n" \
"\n" \
"if it detects that /dev/console is _not_ a serial console, it will also run:\n" \
"\n" \
" tty2::askfirst:/bin/sh\n" \
+" tty3::askfirst:/bin/sh\n" \
+" tty4::askfirst:/bin/sh\n" \
"\n" \
"If you choose to use an /etc/inittab file, the inittab entry format is as follows:\n" \
"\n" \
@@ -692,7 +697,7 @@
" <action>: \n" \
"\n" \
" Valid actions include: sysinit, respawn, askfirst, wait, \n" \
-" once, and ctrlaltdel.\n" \
+" once, ctrlaltdel, and shutdown.\n" \
"\n" \
" The available actions can be classified into two groups: actions\n" \
" that are run only once, and actions that are re-run when the specified\n" \
@@ -706,9 +711,12 @@
" 'wait' actions, like 'sysinit' actions, cause init to wait until\n" \
" the specified task completes. 'once' actions are asyncronous,\n" \
" therefore, init does not wait for them to complete. 'ctrlaltdel'\n" \
-" actions are run immediately before init causes the system to reboot\n" \
-" (unmounting filesystems with a 'ctrlaltdel' action is a very good\n" \
-" idea).\n" \
+" actions are run when the system detects that someone on the system\n" \
+" console has pressed the CTRL-ALT-DEL key combination. Typically one\n" \
+" wants to run 'reboot' at this point to cause the system to reboot.\n" \
+" Finally the 'shutdown' action specifies the actions to taken when\n" \
+" init is told to reboot. Unmounting filesystems and disabling swap\n" \
+" is a very good here\n" \
"\n" \
" Run repeatedly actions:\n" \
"\n" \
@@ -759,8 +767,9 @@
" #::respawn:/sbin/getty 57600 ttyS2\n" \
" \n" \
" # Stuff to do before rebooting\n" \
-" ::ctrlaltdel:/bin/umount -a -r\n" \
-" ::ctrlaltdel:/sbin/swapoff -a\n"
+" ::ctrlaltdel:/sbin/reboot\n" \
+" ::shutdown:/bin/umount -a -r\n" \
+" ::shutdown:/sbin/swapoff -a\n"
#define insmod_trivial_usage \
"[OPTION]... MODULE [symbol=value]..."
diff --git a/init.c b/init.c
index 417aadd..570b8a6 100644
--- a/init.c
+++ b/init.c
@@ -146,7 +146,8 @@
ASKFIRST,
WAIT,
ONCE,
- CTRLALTDEL
+ CTRLALTDEL,
+ SHUTDOWN
} initActionEnum;
/* A mapping between "inittab" action name strings and action type codes. */
@@ -162,6 +163,7 @@
{"wait", WAIT},
{"once", ONCE},
{"ctrlaltdel", CTRLALTDEL},
+ {"shutdown", SHUTDOWN},
{0, 0}
};
@@ -617,12 +619,12 @@
}
/* Run all commands to be run right before halt/reboot */
-static void run_lastAction(void)
+static void run_actions(initActionEnum action)
{
initAction *a, *tmp;
for (a = initActionList; a; a = tmp) {
tmp = a->nextPtr;
- if (a->action == CTRLALTDEL) {
+ if (a->action == action) {
waitfor(a->process, a->console, FALSE);
delete_initAction(a);
}
@@ -654,7 +656,7 @@
sleep(1);
/* run everything to be run at "ctrlaltdel" */
- run_lastAction();
+ run_actions(SHUTDOWN);
sync();
if (kernelVersion > 0 && kernelVersion <= KERNEL_VERSION(2,2,11)) {
@@ -696,6 +698,11 @@
exit(0);
}
+static void ctrlaltdel_signal(int sig)
+{
+ run_actions(CTRLALTDEL);
+}
+
#endif /* ! DEBUG_INIT */
static void new_initAction(initActionEnum action, char *process, char *cons)
@@ -767,10 +774,12 @@
if (file == NULL) {
/* No inittab file -- set up some default behavior */
#endif
+ /* Reboot on Ctrl-Alt-Del */
+ new_initAction(CTRLALTDEL, "/sbin/reboot", console);
/* Swapoff on halt/reboot */
- new_initAction(CTRLALTDEL, "/sbin/swapoff -a", console);
+ new_initAction(SHUTDOWN, "/sbin/swapoff -a", console);
/* Umount all filesystems on halt/reboot */
- new_initAction(CTRLALTDEL, "/bin/umount -a -r", console);
+ new_initAction(SHUTDOWN, "/bin/umount -a -r", console);
/* Askfirst shell on tty1 */
new_initAction(ASKFIRST, SHELL, console);
/* Askfirst shell on tty2 */
@@ -883,7 +892,7 @@
* clear all of these in run() */
signal(SIGUSR1, halt_signal);
signal(SIGUSR2, halt_signal);
- signal(SIGINT, reboot_signal);
+ signal(SIGINT, ctrlaltdel_signal);
signal(SIGTERM, reboot_signal);
/* Turn off rebooting via CTL-ALT-DEL -- we get a
diff --git a/init/init.c b/init/init.c
index 417aadd..570b8a6 100644
--- a/init/init.c
+++ b/init/init.c
@@ -146,7 +146,8 @@
ASKFIRST,
WAIT,
ONCE,
- CTRLALTDEL
+ CTRLALTDEL,
+ SHUTDOWN
} initActionEnum;
/* A mapping between "inittab" action name strings and action type codes. */
@@ -162,6 +163,7 @@
{"wait", WAIT},
{"once", ONCE},
{"ctrlaltdel", CTRLALTDEL},
+ {"shutdown", SHUTDOWN},
{0, 0}
};
@@ -617,12 +619,12 @@
}
/* Run all commands to be run right before halt/reboot */
-static void run_lastAction(void)
+static void run_actions(initActionEnum action)
{
initAction *a, *tmp;
for (a = initActionList; a; a = tmp) {
tmp = a->nextPtr;
- if (a->action == CTRLALTDEL) {
+ if (a->action == action) {
waitfor(a->process, a->console, FALSE);
delete_initAction(a);
}
@@ -654,7 +656,7 @@
sleep(1);
/* run everything to be run at "ctrlaltdel" */
- run_lastAction();
+ run_actions(SHUTDOWN);
sync();
if (kernelVersion > 0 && kernelVersion <= KERNEL_VERSION(2,2,11)) {
@@ -696,6 +698,11 @@
exit(0);
}
+static void ctrlaltdel_signal(int sig)
+{
+ run_actions(CTRLALTDEL);
+}
+
#endif /* ! DEBUG_INIT */
static void new_initAction(initActionEnum action, char *process, char *cons)
@@ -767,10 +774,12 @@
if (file == NULL) {
/* No inittab file -- set up some default behavior */
#endif
+ /* Reboot on Ctrl-Alt-Del */
+ new_initAction(CTRLALTDEL, "/sbin/reboot", console);
/* Swapoff on halt/reboot */
- new_initAction(CTRLALTDEL, "/sbin/swapoff -a", console);
+ new_initAction(SHUTDOWN, "/sbin/swapoff -a", console);
/* Umount all filesystems on halt/reboot */
- new_initAction(CTRLALTDEL, "/bin/umount -a -r", console);
+ new_initAction(SHUTDOWN, "/bin/umount -a -r", console);
/* Askfirst shell on tty1 */
new_initAction(ASKFIRST, SHELL, console);
/* Askfirst shell on tty2 */
@@ -883,7 +892,7 @@
* clear all of these in run() */
signal(SIGUSR1, halt_signal);
signal(SIGUSR2, halt_signal);
- signal(SIGINT, reboot_signal);
+ signal(SIGINT, ctrlaltdel_signal);
signal(SIGTERM, reboot_signal);
/* Turn off rebooting via CTL-ALT-DEL -- we get a
diff --git a/init/reboot.c b/init/reboot.c
index 3e5f238..74d2cf6 100644
--- a/init/reboot.c
+++ b/init/reboot.c
@@ -28,9 +28,9 @@
{
#ifdef BB_FEATURE_LINUXRC
/* don't assume init's pid == 1 */
- return(kill(*(find_pid_by_name("init")), SIGINT));
+ return(kill(*(find_pid_by_name("init")), SIGTERM));
#else
- return(kill(1, SIGINT));
+ return(kill(1, SIGTERM));
#endif
}
diff --git a/reboot.c b/reboot.c
index 3e5f238..74d2cf6 100644
--- a/reboot.c
+++ b/reboot.c
@@ -28,9 +28,9 @@
{
#ifdef BB_FEATURE_LINUXRC
/* don't assume init's pid == 1 */
- return(kill(*(find_pid_by_name("init")), SIGINT));
+ return(kill(*(find_pid_by_name("init")), SIGTERM));
#else
- return(kill(1, SIGINT));
+ return(kill(1, SIGTERM));
#endif
}
diff --git a/usage.h b/usage.h
index 1ee2ab3..aa7f0af 100644
--- a/usage.h
+++ b/usage.h
@@ -663,10 +663,15 @@
"\n" \
" ::sysinit:/etc/init.d/rcS\n" \
" ::askfirst:/bin/sh\n" \
+" ::ctrlaltdel:/sbin/reboot\n" \
+" ::shutdown:/sbin/swapoff -a\n" \
+" ::shutdown:/bin/umount -a -r\n" \
"\n" \
"if it detects that /dev/console is _not_ a serial console, it will also run:\n" \
"\n" \
" tty2::askfirst:/bin/sh\n" \
+" tty3::askfirst:/bin/sh\n" \
+" tty4::askfirst:/bin/sh\n" \
"\n" \
"If you choose to use an /etc/inittab file, the inittab entry format is as follows:\n" \
"\n" \
@@ -692,7 +697,7 @@
" <action>: \n" \
"\n" \
" Valid actions include: sysinit, respawn, askfirst, wait, \n" \
-" once, and ctrlaltdel.\n" \
+" once, ctrlaltdel, and shutdown.\n" \
"\n" \
" The available actions can be classified into two groups: actions\n" \
" that are run only once, and actions that are re-run when the specified\n" \
@@ -706,9 +711,12 @@
" 'wait' actions, like 'sysinit' actions, cause init to wait until\n" \
" the specified task completes. 'once' actions are asyncronous,\n" \
" therefore, init does not wait for them to complete. 'ctrlaltdel'\n" \
-" actions are run immediately before init causes the system to reboot\n" \
-" (unmounting filesystems with a 'ctrlaltdel' action is a very good\n" \
-" idea).\n" \
+" actions are run when the system detects that someone on the system\n" \
+" console has pressed the CTRL-ALT-DEL key combination. Typically one\n" \
+" wants to run 'reboot' at this point to cause the system to reboot.\n" \
+" Finally the 'shutdown' action specifies the actions to taken when\n" \
+" init is told to reboot. Unmounting filesystems and disabling swap\n" \
+" is a very good here\n" \
"\n" \
" Run repeatedly actions:\n" \
"\n" \
@@ -759,8 +767,9 @@
" #::respawn:/sbin/getty 57600 ttyS2\n" \
" \n" \
" # Stuff to do before rebooting\n" \
-" ::ctrlaltdel:/bin/umount -a -r\n" \
-" ::ctrlaltdel:/sbin/swapoff -a\n"
+" ::ctrlaltdel:/sbin/reboot\n" \
+" ::shutdown:/bin/umount -a -r\n" \
+" ::shutdown:/sbin/swapoff -a\n"
#define insmod_trivial_usage \
"[OPTION]... MODULE [symbol=value]..."