diff options
author | andersen <andersen@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2001-04-03 18:01:51 +0000 |
---|---|---|
committer | andersen <andersen@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2001-04-03 18:01:51 +0000 |
commit | 0427b6742d1907d9af79fd93ed021717e71e433b (patch) | |
tree | 113cfd14600fe4ccb65e392eeb06e368df13f1ef /init | |
parent | 525f521dd6a3796012a4a9b476d056a2c4da2d87 (diff) | |
download | busybox-w32-0427b6742d1907d9af79fd93ed021717e71e433b.tar.gz busybox-w32-0427b6742d1907d9af79fd93ed021717e71e433b.tar.bz2 busybox-w32-0427b6742d1907d9af79fd93ed021717e71e433b.zip |
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.
git-svn-id: svn://busybox.net/trunk/busybox@2232 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'init')
-rw-r--r-- | init/init.c | 23 | ||||
-rw-r--r-- | init/reboot.c | 4 |
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 { | |||
146 | ASKFIRST, | 146 | ASKFIRST, |
147 | WAIT, | 147 | WAIT, |
148 | ONCE, | 148 | ONCE, |
149 | CTRLALTDEL | 149 | CTRLALTDEL, |
150 | SHUTDOWN | ||
150 | } initActionEnum; | 151 | } initActionEnum; |
151 | 152 | ||
152 | /* A mapping between "inittab" action name strings and action type codes. */ | 153 | /* A mapping between "inittab" action name strings and action type codes. */ |
@@ -162,6 +163,7 @@ static const struct initActionType actions[] = { | |||
162 | {"wait", WAIT}, | 163 | {"wait", WAIT}, |
163 | {"once", ONCE}, | 164 | {"once", ONCE}, |
164 | {"ctrlaltdel", CTRLALTDEL}, | 165 | {"ctrlaltdel", CTRLALTDEL}, |
166 | {"shutdown", SHUTDOWN}, | ||
165 | {0, 0} | 167 | {0, 0} |
166 | }; | 168 | }; |
167 | 169 | ||
@@ -617,12 +619,12 @@ static void check_memory() | |||
617 | } | 619 | } |
618 | 620 | ||
619 | /* Run all commands to be run right before halt/reboot */ | 621 | /* Run all commands to be run right before halt/reboot */ |
620 | static void run_lastAction(void) | 622 | static void run_actions(initActionEnum action) |
621 | { | 623 | { |
622 | initAction *a, *tmp; | 624 | initAction *a, *tmp; |
623 | for (a = initActionList; a; a = tmp) { | 625 | for (a = initActionList; a; a = tmp) { |
624 | tmp = a->nextPtr; | 626 | tmp = a->nextPtr; |
625 | if (a->action == CTRLALTDEL) { | 627 | if (a->action == action) { |
626 | waitfor(a->process, a->console, FALSE); | 628 | waitfor(a->process, a->console, FALSE); |
627 | delete_initAction(a); | 629 | delete_initAction(a); |
628 | } | 630 | } |
@@ -654,7 +656,7 @@ static void shutdown_system(void) | |||
654 | sleep(1); | 656 | sleep(1); |
655 | 657 | ||
656 | /* run everything to be run at "ctrlaltdel" */ | 658 | /* run everything to be run at "ctrlaltdel" */ |
657 | run_lastAction(); | 659 | run_actions(SHUTDOWN); |
658 | 660 | ||
659 | sync(); | 661 | sync(); |
660 | if (kernelVersion > 0 && kernelVersion <= KERNEL_VERSION(2,2,11)) { | 662 | if (kernelVersion > 0 && kernelVersion <= KERNEL_VERSION(2,2,11)) { |
@@ -696,6 +698,11 @@ static void reboot_signal(int sig) | |||
696 | exit(0); | 698 | exit(0); |
697 | } | 699 | } |
698 | 700 | ||
701 | static void ctrlaltdel_signal(int sig) | ||
702 | { | ||
703 | run_actions(CTRLALTDEL); | ||
704 | } | ||
705 | |||
699 | #endif /* ! DEBUG_INIT */ | 706 | #endif /* ! DEBUG_INIT */ |
700 | 707 | ||
701 | static void new_initAction(initActionEnum action, char *process, char *cons) | 708 | static void new_initAction(initActionEnum action, char *process, char *cons) |
@@ -767,10 +774,12 @@ static void parse_inittab(void) | |||
767 | if (file == NULL) { | 774 | if (file == NULL) { |
768 | /* No inittab file -- set up some default behavior */ | 775 | /* No inittab file -- set up some default behavior */ |
769 | #endif | 776 | #endif |
777 | /* Reboot on Ctrl-Alt-Del */ | ||
778 | new_initAction(CTRLALTDEL, "/sbin/reboot", console); | ||
770 | /* Swapoff on halt/reboot */ | 779 | /* Swapoff on halt/reboot */ |
771 | new_initAction(CTRLALTDEL, "/sbin/swapoff -a", console); | 780 | new_initAction(SHUTDOWN, "/sbin/swapoff -a", console); |
772 | /* Umount all filesystems on halt/reboot */ | 781 | /* Umount all filesystems on halt/reboot */ |
773 | new_initAction(CTRLALTDEL, "/bin/umount -a -r", console); | 782 | new_initAction(SHUTDOWN, "/bin/umount -a -r", console); |
774 | /* Askfirst shell on tty1 */ | 783 | /* Askfirst shell on tty1 */ |
775 | new_initAction(ASKFIRST, SHELL, console); | 784 | new_initAction(ASKFIRST, SHELL, console); |
776 | /* Askfirst shell on tty2 */ | 785 | /* Askfirst shell on tty2 */ |
@@ -883,7 +892,7 @@ extern int init_main(int argc, char **argv) | |||
883 | * clear all of these in run() */ | 892 | * clear all of these in run() */ |
884 | signal(SIGUSR1, halt_signal); | 893 | signal(SIGUSR1, halt_signal); |
885 | signal(SIGUSR2, halt_signal); | 894 | signal(SIGUSR2, halt_signal); |
886 | signal(SIGINT, reboot_signal); | 895 | signal(SIGINT, ctrlaltdel_signal); |
887 | signal(SIGTERM, reboot_signal); | 896 | signal(SIGTERM, reboot_signal); |
888 | 897 | ||
889 | /* Turn off rebooting via CTL-ALT-DEL -- we get a | 898 | /* 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) | |||
28 | { | 28 | { |
29 | #ifdef BB_FEATURE_LINUXRC | 29 | #ifdef BB_FEATURE_LINUXRC |
30 | /* don't assume init's pid == 1 */ | 30 | /* don't assume init's pid == 1 */ |
31 | return(kill(*(find_pid_by_name("init")), SIGINT)); | 31 | return(kill(*(find_pid_by_name("init")), SIGTERM)); |
32 | #else | 32 | #else |
33 | return(kill(1, SIGINT)); | 33 | return(kill(1, SIGTERM)); |
34 | #endif | 34 | #endif |
35 | } | 35 | } |
36 | 36 | ||