aboutsummaryrefslogtreecommitdiff
path: root/init
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2001-04-03 18:01:51 +0000
committerEric Andersen <andersen@codepoet.org>2001-04-03 18:01:51 +0000
commitc97ec34370f66771713809ab7da19b7fe923cffe (patch)
tree113cfd14600fe4ccb65e392eeb06e368df13f1ef /init
parent0f0c0b41ced8c30d382a0490719c79371260b9d1 (diff)
downloadbusybox-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')
-rw-r--r--init/init.c23
-rw-r--r--init/reboot.c4
2 files changed, 18 insertions, 9 deletions
diff --git a/init/init.c b/init/init.c
index 417aadd23..570b8a697 100644
--- a/init/init.c
+++ b/init/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
diff --git a/init/reboot.c b/init/reboot.c
index 3e5f2382c..74d2cf643 100644
--- a/init/reboot.c
+++ b/init/reboot.c
@@ -28,9 +28,9 @@ extern int reboot_main(int argc, char **argv)
{
#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
}