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 | |
| 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
| -rw-r--r-- | examples/inittab | 7 | ||||
| -rw-r--r-- | include/usage.h | 11 | ||||
| -rw-r--r-- | init/init.c | 33 |
3 files changed, 47 insertions, 4 deletions
diff --git a/examples/inittab b/examples/inittab index 45f5a61fe..4eed84885 100644 --- a/examples/inittab +++ b/examples/inittab | |||
| @@ -24,7 +24,7 @@ | |||
| 24 | # <runlevels>: The runlevels field is completely ignored. | 24 | # <runlevels>: The runlevels field is completely ignored. |
| 25 | # | 25 | # |
| 26 | # <action>: Valid actions include: sysinit, respawn, askfirst, wait, once, | 26 | # <action>: Valid actions include: sysinit, respawn, askfirst, wait, once, |
| 27 | # ctrlaltdel, and shutdown. | 27 | # restart, ctrlaltdel, and shutdown. |
| 28 | # | 28 | # |
| 29 | # Note: askfirst acts just like respawn, but before running the specified | 29 | # Note: askfirst acts just like respawn, but before running the specified |
| 30 | # process it displays the line "Please press Enter to activate this | 30 | # process it displays the line "Please press Enter to activate this |
| @@ -43,6 +43,8 @@ | |||
| 43 | # ::ctrlaltdel:/sbin/reboot | 43 | # ::ctrlaltdel:/sbin/reboot |
| 44 | # ::shutdown:/sbin/swapoff -a | 44 | # ::shutdown:/sbin/swapoff -a |
| 45 | # ::shutdown:/bin/umount -a -r | 45 | # ::shutdown:/bin/umount -a -r |
| 46 | # ::restart:/sbin/init | ||
| 47 | # | ||
| 46 | # if it detects that /dev/console is _not_ a serial console, it will | 48 | # if it detects that /dev/console is _not_ a serial console, it will |
| 47 | # also run: | 49 | # also run: |
| 48 | # tty2::askfirst:/bin/sh | 50 | # tty2::askfirst:/bin/sh |
| @@ -79,6 +81,9 @@ tty5::respawn:/sbin/getty 38400 tty6 | |||
| 79 | # Example how to put a getty on a modem line. | 81 | # Example how to put a getty on a modem line. |
| 80 | #::respawn:/sbin/getty 57600 ttyS2 | 82 | #::respawn:/sbin/getty 57600 ttyS2 |
| 81 | 83 | ||
| 84 | # Stuff to do when restarting the init process | ||
| 85 | ::restart:/sbin/init | ||
| 86 | |||
| 82 | # Stuff to do before rebooting | 87 | # Stuff to do before rebooting |
| 83 | ::ctrlaltdel:/sbin/reboot | 88 | ::ctrlaltdel:/sbin/reboot |
| 84 | ::shutdown:/bin/umount -a -r | 89 | ::shutdown:/bin/umount -a -r |
diff --git a/include/usage.h b/include/usage.h index b84cdd5e3..a970c0f9c 100644 --- a/include/usage.h +++ b/include/usage.h | |||
| @@ -765,6 +765,7 @@ | |||
| 765 | " ::ctrlaltdel:/sbin/reboot\n" \ | 765 | " ::ctrlaltdel:/sbin/reboot\n" \ |
| 766 | " ::shutdown:/sbin/swapoff -a\n" \ | 766 | " ::shutdown:/sbin/swapoff -a\n" \ |
| 767 | " ::shutdown:/bin/umount -a -r\n" \ | 767 | " ::shutdown:/bin/umount -a -r\n" \ |
| 768 | " ::restart:/sbin/init\n" \ | ||
| 768 | "\n" \ | 769 | "\n" \ |
| 769 | "if it detects that /dev/console is _not_ a serial console, it will also run:\n" \ | 770 | "if it detects that /dev/console is _not_ a serial console, it will also run:\n" \ |
| 770 | "\n" \ | 771 | "\n" \ |
| @@ -796,7 +797,7 @@ | |||
| 796 | " <action>: \n" \ | 797 | " <action>: \n" \ |
| 797 | "\n" \ | 798 | "\n" \ |
| 798 | " Valid actions include: sysinit, respawn, askfirst, wait, \n" \ | 799 | " Valid actions include: sysinit, respawn, askfirst, wait, \n" \ |
| 799 | " once, ctrlaltdel, and shutdown.\n" \ | 800 | " once, restart, ctrlaltdel, and shutdown.\n" \ |
| 800 | "\n" \ | 801 | "\n" \ |
| 801 | " The available actions can be classified into two groups: actions\n" \ | 802 | " The available actions can be classified into two groups: actions\n" \ |
| 802 | " that are run only once, and actions that are re-run when the specified\n" \ | 803 | " that are run only once, and actions that are re-run when the specified\n" \ |
| @@ -809,7 +810,10 @@ | |||
| 809 | " completion of all sysinit actions, all 'wait' actions are run.\n" \ | 810 | " completion of all sysinit actions, all 'wait' actions are run.\n" \ |
| 810 | " 'wait' actions, like 'sysinit' actions, cause init to wait until\n" \ | 811 | " 'wait' actions, like 'sysinit' actions, cause init to wait until\n" \ |
| 811 | " the specified task completes. 'once' actions are asynchronous,\n" \ | 812 | " the specified task completes. 'once' actions are asynchronous,\n" \ |
| 812 | " therefore, init does not wait for them to complete. 'ctrlaltdel'\n" \ | 813 | " therefore, init does not wait for them to complete. 'restart' is\n" \ |
| 814 | " the action taken to restart the init process. By default this should\n" \ | ||
| 815 | " simply run /sbin/init, but can be a script which runs pivot_root or it\n" \ | ||
| 816 | " can do all sorts of other interesting things. The 'ctrlaltdel' init\n" \ | ||
| 813 | " actions are run when the system detects that someone on the system\n" \ | 817 | " actions are run when the system detects that someone on the system\n" \ |
| 814 | " console has pressed the CTRL-ALT-DEL key combination. Typically one\n" \ | 818 | " console has pressed the CTRL-ALT-DEL key combination. Typically one\n" \ |
| 815 | " wants to run 'reboot' at this point to cause the system to reboot.\n" \ | 819 | " wants to run 'reboot' at this point to cause the system to reboot.\n" \ |
| @@ -865,6 +869,9 @@ | |||
| 865 | " # Example how to put a getty on a modem line.\n" \ | 869 | " # Example how to put a getty on a modem line.\n" \ |
| 866 | " #::respawn:/sbin/getty 57600 ttyS2\n" \ | 870 | " #::respawn:/sbin/getty 57600 ttyS2\n" \ |
| 867 | " \n" \ | 871 | " \n" \ |
| 872 | " # Stuff to do when restarting the init process\n" \ | ||
| 873 | " ::restart:/sbin/init\n" \ | ||
| 874 | " \n" \ | ||
| 868 | " # Stuff to do before rebooting\n" \ | 875 | " # Stuff to do before rebooting\n" \ |
| 869 | " ::ctrlaltdel:/sbin/reboot\n" \ | 876 | " ::ctrlaltdel:/sbin/reboot\n" \ |
| 870 | " ::shutdown:/bin/umount -a -r\n" \ | 877 | " ::shutdown:/bin/umount -a -r\n" \ |
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); |
