diff options
author | andersen <andersen@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2001-12-17 23:13:08 +0000 |
---|---|---|
committer | andersen <andersen@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2001-12-17 23:13:08 +0000 |
commit | da8053784e7964b7763eca7e83fa85cf5cb00f1b (patch) | |
tree | adf3d068d584f3fe5a25286d0ebadf123dd584d0 /init | |
parent | a71ab54376eed7d51c028ca7986fa7667417d3c7 (diff) | |
download | busybox-w32-da8053784e7964b7763eca7e83fa85cf5cb00f1b.tar.gz busybox-w32-da8053784e7964b7763eca7e83fa85cf5cb00f1b.tar.bz2 busybox-w32-da8053784e7964b7763eca7e83fa85cf5cb00f1b.zip |
Add in a new restart init target, triggered by SIGHUP. Patch from
Russ Dill, with adjustments by me.
-Erik
git-svn-id: svn://busybox.net/trunk/busybox@3896 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'init')
-rw-r--r-- | init/init.c | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/init/init.c b/init/init.c index d0beb2a9a..f6108f1e8 100644 --- a/init/init.c +++ b/init/init.c | |||
@@ -142,7 +142,8 @@ typedef enum { | |||
142 | WAIT, | 142 | WAIT, |
143 | ONCE, | 143 | ONCE, |
144 | CTRLALTDEL, | 144 | CTRLALTDEL, |
145 | SHUTDOWN | 145 | SHUTDOWN, |
146 | RESTART | ||
146 | } initActionEnum; | 147 | } initActionEnum; |
147 | 148 | ||
148 | /* A mapping between "inittab" action name strings and action type codes. */ | 149 | /* A mapping between "inittab" action name strings and action type codes. */ |
@@ -159,6 +160,7 @@ static const struct initActionType actions[] = { | |||
159 | {"once", ONCE}, | 160 | {"once", ONCE}, |
160 | {"ctrlaltdel", CTRLALTDEL}, | 161 | {"ctrlaltdel", CTRLALTDEL}, |
161 | {"shutdown", SHUTDOWN}, | 162 | {"shutdown", SHUTDOWN}, |
163 | {"restart", RESTART}, | ||
162 | {0, 0} | 164 | {0, 0} |
163 | }; | 165 | }; |
164 | 166 | ||
@@ -688,6 +690,26 @@ static void shutdown_system(void) | |||
688 | } | 690 | } |
689 | } | 691 | } |
690 | 692 | ||
693 | static void exec_signal(int sig) | ||
694 | { | ||
695 | initAction *a, *tmp; | ||
696 | for (a = initActionList; a; a = tmp) { | ||
697 | tmp = a->nextPtr; | ||
698 | if (a->action == RESTART) { | ||
699 | shutdown_system(); | ||
700 | message(CONSOLE|LOG, "Trying to re-exec %s\n", a->process); | ||
701 | execl(a->process, a->process, NULL); | ||
702 | |||
703 | message(CONSOLE|LOG, "execl of %s failed: %s\n", | ||
704 | a->process, sys_errlist[errno]); | ||
705 | sync(); | ||
706 | sleep(2); | ||
707 | init_reboot(RB_HALT_SYSTEM); | ||
708 | loop_forever(); | ||
709 | } | ||
710 | } | ||
711 | } | ||
712 | |||
691 | static void halt_signal(int sig) | 713 | static void halt_signal(int sig) |
692 | { | 714 | { |
693 | shutdown_system(); | 715 | shutdown_system(); |
@@ -839,6 +861,8 @@ static void parse_inittab(void) | |||
839 | /* Swapoff on halt/reboot */ | 861 | /* Swapoff on halt/reboot */ |
840 | new_initAction(SHUTDOWN, "/sbin/swapoff -a", console); | 862 | new_initAction(SHUTDOWN, "/sbin/swapoff -a", console); |
841 | #endif | 863 | #endif |
864 | /* Prepare to restart init when a HUP is received */ | ||
865 | new_initAction(RESTART, "/sbin/init", console); | ||
842 | /* Askfirst shell on tty1 */ | 866 | /* Askfirst shell on tty1 */ |
843 | new_initAction(ASKFIRST, LOGIN_SHELL, console); | 867 | new_initAction(ASKFIRST, LOGIN_SHELL, console); |
844 | /* Askfirst shell on tty2 */ | 868 | /* Askfirst shell on tty2 */ |
@@ -937,6 +961,12 @@ extern int init_main(int argc, char **argv) | |||
937 | pid_t wpid; | 961 | pid_t wpid; |
938 | int status; | 962 | int status; |
939 | 963 | ||
964 | |||
965 | if (argc > 1 && !strcmp(argv[1], "-q")) { | ||
966 | kill(1, SIGHUP); | ||
967 | exit(0); | ||
968 | } | ||
969 | |||
940 | #ifndef DEBUG_INIT | 970 | #ifndef DEBUG_INIT |
941 | /* Expect to be invoked as init with PID=1 or be invoked as linuxrc */ | 971 | /* Expect to be invoked as init with PID=1 or be invoked as linuxrc */ |
942 | if (getpid() != 1 | 972 | if (getpid() != 1 |
@@ -949,6 +979,7 @@ extern int init_main(int argc, char **argv) | |||
949 | } | 979 | } |
950 | /* Set up sig handlers -- be sure to | 980 | /* Set up sig handlers -- be sure to |
951 | * clear all of these in run() */ | 981 | * clear all of these in run() */ |
982 | signal(SIGHUP, exec_signal); | ||
952 | signal(SIGUSR1, halt_signal); | 983 | signal(SIGUSR1, halt_signal); |
953 | signal(SIGUSR2, halt_signal); | 984 | signal(SIGUSR2, halt_signal); |
954 | signal(SIGINT, ctrlaltdel_signal); | 985 | signal(SIGINT, ctrlaltdel_signal); |