diff options
| author | landley <landley@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2006-01-30 08:31:37 +0000 |
|---|---|---|
| committer | landley <landley@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2006-01-30 08:31:37 +0000 |
| commit | 2a15429d2b98f520c67bbd593a173786dcafab4d (patch) | |
| tree | 1e57cdfe9be4ec15c27276389a760f3ad6b5ab34 /init | |
| parent | b5138e1bb1d647e9718e2dc4929c30a6d7a62eaa (diff) | |
| download | busybox-w32-2a15429d2b98f520c67bbd593a173786dcafab4d.tar.gz busybox-w32-2a15429d2b98f520c67bbd593a173786dcafab4d.tar.bz2 busybox-w32-2a15429d2b98f520c67bbd593a173786dcafab4d.zip | |
Re-add initrd support, unify halt/reboot/poweroff, add -n and -f options.
git-svn-id: svn://busybox.net/trunk/busybox@13701 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'init')
| -rw-r--r-- | init/Config.in | 55 | ||||
| -rw-r--r-- | init/halt.c | 38 | ||||
| -rw-r--r-- | init/init.c | 17 | ||||
| -rw-r--r-- | init/poweroff.c | 28 | ||||
| -rw-r--r-- | init/reboot.c | 28 |
5 files changed, 56 insertions, 110 deletions
diff --git a/init/Config.in b/init/Config.in index ba157081c..d5af54e47 100644 --- a/init/Config.in +++ b/init/Config.in | |||
| @@ -12,21 +12,32 @@ config CONFIG_INIT | |||
| 12 | init is the first program run when the system boots. | 12 | init is the first program run when the system boots. |
| 13 | 13 | ||
| 14 | config CONFIG_FEATURE_USE_INITTAB | 14 | config CONFIG_FEATURE_USE_INITTAB |
| 15 | bool " Support reading an inittab file?" | 15 | bool " Support reading an inittab file" |
| 16 | default y | 16 | default y |
| 17 | depends on CONFIG_INIT | 17 | depends on CONFIG_INIT |
| 18 | help | 18 | help |
| 19 | Allow init to read an inittab file when the system boot. | 19 | Allow init to read an inittab file when the system boot. |
| 20 | 20 | ||
| 21 | config CONFIG_FEATURE_INITRD | 21 | config CONFIG_FEATURE_INIT_SCTTY |
| 22 | bool " Support running init from within an initrd?" | 22 | bool " Support running commands with a controlling-tty" |
| 23 | default n | ||
| 24 | depends on CONFIG_INIT | ||
| 25 | help | ||
| 26 | If this option is enabled a command starting with hyphen (-) | ||
| 27 | is run in its own session (setsid(2)) and possibly with a | ||
| 28 | controlling tty (TIOCSCTTY). This is not the traditional init | ||
| 29 | behavour, but is often what you want in an embedded system where | ||
| 30 | the console is only accessed during development or for maintenance. | ||
| 31 | |||
| 32 | config CONFIG_FEATURE_EXTRA_QUIET | ||
| 33 | bool " Be _extra_ quiet on boot" | ||
| 23 | default y | 34 | default y |
| 24 | depends on CONFIG_INIT | 35 | depends on CONFIG_INIT |
| 25 | help | 36 | help |
| 26 | Allow init to be called from an initrd as linuxrc. | 37 | Prevent init from logging some messages to the console during boot. |
| 27 | 38 | ||
| 28 | config CONFIG_FEATURE_INIT_COREDUMPS | 39 | config CONFIG_FEATURE_INIT_COREDUMPS |
| 29 | bool " Support dumping core for child processes (debugging only)?" | 40 | bool " Support dumping core for child processes (debugging only)" |
| 30 | default n | 41 | default n |
| 31 | depends on CONFIG_INIT | 42 | depends on CONFIG_INIT |
| 32 | help | 43 | help |
| @@ -35,30 +46,24 @@ config CONFIG_FEATURE_INIT_COREDUMPS | |||
| 35 | core file sizes. If this option is disabled, processes | 46 | core file sizes. If this option is disabled, processes |
| 36 | will not generate any core files. | 47 | will not generate any core files. |
| 37 | 48 | ||
| 38 | config CONFIG_FEATURE_INIT_SCTTY | ||
| 39 | bool " Support running commands with a controlling-tty?" | ||
| 40 | default n | ||
| 41 | depends on CONFIG_INIT | ||
| 42 | help | ||
| 43 | If this option is enabled a command starting with hyphen (-) | ||
| 44 | is run in its own session (setsid(2)) and possibly with a | ||
| 45 | controlling tty (TIOCSCTTY). This is not the traditional init | ||
| 46 | behavour, but is often what you want in an embedded system where | ||
| 47 | the console is only accessed during development or for maintenance. | ||
| 48 | 49 | ||
| 49 | config CONFIG_FEATURE_EXTRA_QUIET | 50 | |
| 50 | bool " Should init be _extra_ quiet on boot?" | 51 | config CONFIG_FEATURE_INITRD |
| 52 | bool " Support running init from within an initrd (not initramfs)" | ||
| 51 | default y | 53 | default y |
| 52 | depends on CONFIG_INIT | 54 | depends on CONFIG_INIT |
| 53 | help | 55 | help |
| 54 | Prevent init from logging some messages to the console | 56 | Legacy support for running init under the old-style initrd. Allows |
| 55 | during boot. | 57 | the name linuxrc to act as init, and it doesn't assume init is PID 1. |
| 58 | |||
| 59 | This does not apply to initramfs, which runs /init as PID 1 and | ||
| 60 | requires no special support. | ||
| 56 | 61 | ||
| 57 | config CONFIG_HALT | 62 | config CONFIG_HALT |
| 58 | bool "halt" | 63 | bool "poweroff, halt, and reboot" |
| 59 | default y | 64 | default y |
| 60 | help | 65 | help |
| 61 | Stop all processes and halt the system. | 66 | Stop all processes and either halt, reboot, or power off the system. |
| 62 | 67 | ||
| 63 | config CONFIG_MESG | 68 | config CONFIG_MESG |
| 64 | bool "mesg" | 69 | bool "mesg" |
| @@ -67,17 +72,9 @@ config CONFIG_MESG | |||
| 67 | Mesg controls access to your terminal by others. It is typically | 72 | Mesg controls access to your terminal by others. It is typically |
| 68 | used to allow or disallow other users to write to your terminal | 73 | used to allow or disallow other users to write to your terminal |
| 69 | 74 | ||
| 70 | config CONFIG_POWEROFF | ||
| 71 | bool "poweroff" | ||
| 72 | default y | 75 | default y |
| 73 | help | 76 | help |
| 74 | Stop all processes and (try to) power off the system. | 77 | Stop all processes and (try to) power off the system. |
| 75 | 78 | ||
| 76 | config CONFIG_REBOOT | ||
| 77 | bool "reboot" | ||
| 78 | default y | ||
| 79 | help | ||
| 80 | Stop all processes and reboot the system. | ||
| 81 | |||
| 82 | endmenu | 79 | endmenu |
| 83 | 80 | ||
diff --git a/init/halt.c b/init/halt.c index 89efdd64a..34479742e 100644 --- a/init/halt.c +++ b/init/halt.c | |||
| @@ -1,28 +1,42 @@ | |||
| 1 | /* vi: set sw=4 ts=4: */ | 1 | /* vi: set sw=4 ts=4: */ |
| 2 | /* | 2 | /* |
| 3 | * Mini halt implementation for busybox | 3 | * Poweroff reboot and halt, oh my. |
| 4 | * | 4 | * |
| 5 | * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org> | 5 | * Copyright 2006 by Rob Landley <rob@landley.net> |
| 6 | * | 6 | * |
| 7 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. | 7 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
| 8 | */ | 8 | */ |
| 9 | 9 | ||
| 10 | #include <signal.h> | 10 | #include <signal.h> |
| 11 | #include <stdlib.h> | ||
| 12 | #include <unistd.h> | ||
| 13 | #include <getopt.h> | ||
| 14 | #include <sys/reboot.h> | 11 | #include <sys/reboot.h> |
| 15 | #include "busybox.h" | 12 | #include "busybox.h" |
| 16 | #include "init_shared.h" | ||
| 17 | 13 | ||
| 14 | #include <unistd.h> | ||
| 18 | 15 | ||
| 19 | extern int halt_main(int argc, char **argv) | 16 | int halt_main(int argc, char *argv[]) |
| 20 | { | 17 | { |
| 21 | char *delay; /* delay in seconds before rebooting */ | 18 | char *delay = "hpr"; |
| 19 | int which, flags, magic[] = {RB_HALT_SYSTEM, RB_POWER_OFF, RB_AUTOBOOT}, | ||
| 20 | signals[] = {SIGUSR1, SIGUSR2, SIGTERM}, rc = 1; | ||
| 21 | |||
| 22 | /* Figure out which applet we're running */ | ||
| 23 | for(which=0;delay[which]!=*bb_applet_name;which++); | ||
| 22 | 24 | ||
| 23 | if(bb_getopt_ulflags(argc, argv, "d:", &delay)) { | 25 | /* Parse and handle arguments */ |
| 24 | sleep(atoi(delay)); | 26 | flags = bb_getopt_ulflags(argc, argv, "d:nf", &delay); |
| 25 | } | 27 | if (flags&1) sleep(atoi(delay)); |
| 28 | if (!(flags&2)) sync(); | ||
| 29 | |||
| 30 | /* Perform action. */ | ||
| 31 | if (ENABLE_INIT && !(flags & 4)) { | ||
| 32 | if (ENABLE_FEATURE_INITRD) { | ||
| 33 | long *pidlist=find_pid_by_name("linuxrc"); | ||
| 34 | if (*pidlist>0) rc = kill(*pidlist,signals[which]); | ||
| 35 | if (ENABLE_FEATURE_CLEAN_UP) free(pidlist); | ||
| 36 | } | ||
| 37 | if (rc) rc = kill(1,signals[which]); | ||
| 38 | } else rc = reboot(magic[which]); | ||
| 26 | 39 | ||
| 27 | return ENABLE_INIT ? kill(1,SIGUSR1) : bb_shutdown_system(RB_HALT_SYSTEM); | 40 | if (rc) bb_error_msg("No."); |
| 41 | return rc; | ||
| 28 | } | 42 | } |
diff --git a/init/init.c b/init/init.c index 337d31c2d..0db355413 100644 --- a/init/init.c +++ b/init/init.c | |||
| @@ -751,14 +751,7 @@ static void exec_signal(int sig) | |||
| 751 | static void halt_signal(int sig) | 751 | static void halt_signal(int sig) |
| 752 | { | 752 | { |
| 753 | shutdown_system(); | 753 | shutdown_system(); |
| 754 | message(CONSOLE | LOG, | 754 | message(CONSOLE | LOG, "The system is halted."); |
| 755 | #if #cpu(s390) | ||
| 756 | /* Seems the s390 console is Wierd(tm). */ | ||
| 757 | "The system is halted. You may reboot now." | ||
| 758 | #else | ||
| 759 | "The system is halted. Press Reset or turn off power" | ||
| 760 | #endif | ||
| 761 | ); | ||
| 762 | sync(); | 755 | sync(); |
| 763 | 756 | ||
| 764 | /* allow time for last message to reach serial console */ | 757 | /* allow time for last message to reach serial console */ |
| @@ -1024,11 +1017,9 @@ extern int init_main(int argc, char **argv) | |||
| 1024 | } | 1017 | } |
| 1025 | #ifndef DEBUG_INIT | 1018 | #ifndef DEBUG_INIT |
| 1026 | /* Expect to be invoked as init with PID=1 or be invoked as linuxrc */ | 1019 | /* Expect to be invoked as init with PID=1 or be invoked as linuxrc */ |
| 1027 | if (getpid() != 1 | 1020 | if (getpid() != 1 && |
| 1028 | #ifdef CONFIG_FEATURE_INITRD | 1021 | (!ENABLE_FEATURE_INITRD || !strstr(bb_applet_name, "linuxrc"))) |
| 1029 | && strstr(bb_applet_name, "linuxrc") == NULL | 1022 | { |
| 1030 | #endif | ||
| 1031 | ) { | ||
| 1032 | bb_show_usage(); | 1023 | bb_show_usage(); |
| 1033 | } | 1024 | } |
| 1034 | /* Set up sig handlers -- be sure to | 1025 | /* Set up sig handlers -- be sure to |
diff --git a/init/poweroff.c b/init/poweroff.c deleted file mode 100644 index b79bcd036..000000000 --- a/init/poweroff.c +++ /dev/null | |||
| @@ -1,28 +0,0 @@ | |||
| 1 | /* vi: set sw=4 ts=4: */ | ||
| 2 | /* | ||
| 3 | * Mini poweroff implementation for busybox | ||
| 4 | * | ||
| 5 | * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org> | ||
| 6 | * | ||
| 7 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. | ||
| 8 | */ | ||
| 9 | |||
| 10 | #include <signal.h> | ||
| 11 | #include <stdlib.h> | ||
| 12 | #include <unistd.h> | ||
| 13 | #include <getopt.h> | ||
| 14 | #include <sys/reboot.h> | ||
| 15 | #include "busybox.h" | ||
| 16 | #include "init_shared.h" | ||
| 17 | |||
| 18 | |||
| 19 | extern int poweroff_main(int argc, char **argv) | ||
| 20 | { | ||
| 21 | char *delay; /* delay in seconds before rebooting */ | ||
| 22 | |||
| 23 | if(bb_getopt_ulflags(argc, argv, "d:", &delay)) { | ||
| 24 | sleep(atoi(delay)); | ||
| 25 | } | ||
| 26 | |||
| 27 | return ENABLE_INIT ? kill(1,SIGUSR2) : bb_shutdown_system(RB_POWER_OFF); | ||
| 28 | } | ||
diff --git a/init/reboot.c b/init/reboot.c deleted file mode 100644 index 5508f0be9..000000000 --- a/init/reboot.c +++ /dev/null | |||
| @@ -1,28 +0,0 @@ | |||
| 1 | /* vi: set sw=4 ts=4: */ | ||
| 2 | /* | ||
| 3 | * Mini reboot implementation for busybox | ||
| 4 | * | ||
| 5 | * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org> | ||
| 6 | * | ||
| 7 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. | ||
| 8 | */ | ||
| 9 | |||
| 10 | #include <signal.h> | ||
| 11 | #include <stdlib.h> | ||
| 12 | #include <unistd.h> | ||
| 13 | #include <getopt.h> | ||
| 14 | #include <sys/reboot.h> | ||
| 15 | #include "busybox.h" | ||
| 16 | #include "init_shared.h" | ||
| 17 | |||
| 18 | |||
| 19 | extern int reboot_main(int argc, char **argv) | ||
| 20 | { | ||
| 21 | char *delay; /* delay in seconds before rebooting */ | ||
| 22 | |||
| 23 | if(bb_getopt_ulflags(argc, argv, "d:", &delay)) { | ||
| 24 | sleep(atoi(delay)); | ||
| 25 | } | ||
| 26 | |||
| 27 | return ENABLE_INIT ? kill(1,SIGTERM) : bb_shutdown_system(RB_AUTOBOOT); | ||
| 28 | } | ||
