summaryrefslogtreecommitdiff
path: root/init.c
diff options
context:
space:
mode:
authorEric Andersen2001-04-03 18:01:51 +0000
committerEric Andersen2001-04-03 18:01:51 +0000
commitc97ec34370f66771713809ab7da19b7fe923cffe (patch)
tree113cfd14600fe4ccb65e392eeb06e368df13f1ef /init.c
parent0f0c0b41ced8c30d382a0490719c79371260b9d1 (diff)
downloadbusybox-c97ec34370f66771713809ab7da19b7fe923cffe.zip
busybox-c97ec34370f66771713809ab7da19b7fe923cffe.tar.gz
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.
Diffstat (limited to 'init.c')
-rw-r--r--init.c23
1 files changed, 16 insertions, 7 deletions
diff --git a/init.c b/init.c
index 417aadd..570b8a6 100644
--- a/init.c
+++ b/init.c
@@ -146,7 +146,8 @@ typedef enum {
ASKFIRST,
WAIT,
ONCE,
- CTRLALTDEL
+ CTRLALTDEL,
+ SHUTDOWN
} initActionEnum;
/* A mapping between "inittab" action name strings and action type codes. */
@@ -162,6 +163,7 @@ static const struct initActionType actions[] = {
{"wait", WAIT},
{"once", ONCE},
{"ctrlaltdel", CTRLALTDEL},
+ {"shutdown", SHUTDOWN},
{0, 0}
};
@@ -617,12 +619,12 @@ static void check_memory()
}
/* 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 @@ static void shutdown_system(void)
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 @@ static void reboot_signal(int sig)
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 @@ static void parse_inittab(void)
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 @@ extern int init_main(int argc, char **argv)
* 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