diff options
| author | andersen <andersen@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2003-07-22 09:41:39 +0000 |
|---|---|---|
| committer | andersen <andersen@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2003-07-22 09:41:39 +0000 |
| commit | 932734db6ba4f5aa3830833f70aa99e03a453525 (patch) | |
| tree | a254319c3697e8f1493373cd1148a6aa1e74a6a6 /init | |
| parent | fa8cf20631cf02ae3e6b0db95a494261df1aee27 (diff) | |
| download | busybox-w32-932734db6ba4f5aa3830833f70aa99e03a453525.tar.gz busybox-w32-932734db6ba4f5aa3830833f70aa99e03a453525.tar.bz2 busybox-w32-932734db6ba4f5aa3830833f70aa99e03a453525.zip | |
Support reboot, halt, and poweroff independent of busybox init.
Simplify and fixup some logic.
-Erik
git-svn-id: svn://busybox.net/trunk/busybox@7091 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'init')
| -rw-r--r-- | init/Config.in | 9 | ||||
| -rw-r--r-- | init/halt.c | 20 | ||||
| -rw-r--r-- | init/init_shared.c | 81 | ||||
| -rw-r--r-- | init/init_shared.h | 2 | ||||
| -rw-r--r-- | init/poweroff.c | 30 | ||||
| -rw-r--r-- | init/reboot.c | 39 |
6 files changed, 136 insertions, 45 deletions
diff --git a/init/Config.in b/init/Config.in index c8c6a9cd6..af7aac833 100644 --- a/init/Config.in +++ b/init/Config.in | |||
| @@ -27,7 +27,7 @@ config CONFIG_FEATURE_INITRD | |||
| 27 | 27 | ||
| 28 | config CONFIG_FEATURE_INIT_COREDUMPS | 28 | config CONFIG_FEATURE_INIT_COREDUMPS |
| 29 | bool " Support dumping core for child processes (debugging only)?" | 29 | bool " Support dumping core for child processes (debugging only)?" |
| 30 | default y | 30 | default n |
| 31 | depends on CONFIG_INIT | 31 | depends on CONFIG_INIT |
| 32 | help | 32 | help |
| 33 | If this option is enabled and the file /.init_enable_core | 33 | If this option is enabled and the file /.init_enable_core |
| @@ -43,31 +43,28 @@ config CONFIG_FEATURE_EXTRA_QUIET | |||
| 43 | Prevent init from logging some messages to the console | 43 | Prevent init from logging some messages to the console |
| 44 | during boot. | 44 | during boot. |
| 45 | 45 | ||
| 46 | # Some apps that are meaningless without BusyBox running as init | ||
| 47 | config CONFIG_HALT | 46 | config CONFIG_HALT |
| 48 | bool "halt" | 47 | bool "halt" |
| 49 | default y | 48 | default y |
| 50 | depends on CONFIG_INIT | ||
| 51 | help | 49 | help |
| 52 | 'halt' tells the kernel to stop all processes and halt the system. | 50 | Stop all processes and halt the system. |
| 53 | 51 | ||
| 54 | config CONFIG_POWEROFF | 52 | config CONFIG_POWEROFF |
| 55 | bool "poweroff" | 53 | bool "poweroff" |
| 56 | default y | 54 | default y |
| 57 | depends on CONFIG_INIT | ||
| 58 | help | 55 | help |
| 59 | Stop all processes and (try to) power off the system. | 56 | Stop all processes and (try to) power off the system. |
| 60 | 57 | ||
| 61 | config CONFIG_REBOOT | 58 | config CONFIG_REBOOT |
| 62 | bool "reboot" | 59 | bool "reboot" |
| 63 | default y | 60 | default y |
| 64 | depends on CONFIG_INIT | ||
| 65 | help | 61 | help |
| 66 | Stop all processes and reboot the system. | 62 | Stop all processes and reboot the system. |
| 67 | 63 | ||
| 68 | config CONFIG_MINIT | 64 | config CONFIG_MINIT |
| 69 | bool "minit" | 65 | bool "minit" |
| 70 | default n | 66 | default n |
| 67 | depends on ! CONFIG_INIT | ||
| 71 | help | 68 | help |
| 72 | Minimal init, based on minit v0.9.1. This is a simple | 69 | Minimal init, based on minit v0.9.1. This is a simple |
| 73 | init replacement that handles starting/stopping services, | 70 | init replacement that handles starting/stopping services, |
diff --git a/init/halt.c b/init/halt.c index 10f16c75d..decdaeafd 100644 --- a/init/halt.c +++ b/init/halt.c | |||
| @@ -2,7 +2,6 @@ | |||
| 2 | /* | 2 | /* |
| 3 | * Mini halt implementation for busybox | 3 | * Mini halt implementation for busybox |
| 4 | * | 4 | * |
| 5 | * Copyright (C) 1995, 1996 by Bruce Perens <bruce@pixar.com>. | ||
| 6 | * Copyright (C) 1999-2003 by Erik Andersen <andersen@codepoet.org> | 5 | * Copyright (C) 1999-2003 by Erik Andersen <andersen@codepoet.org> |
| 7 | * | 6 | * |
| 8 | * This program is free software; you can redistribute it and/or modify | 7 | * This program is free software; you can redistribute it and/or modify |
| @@ -21,12 +20,29 @@ | |||
| 21 | * | 20 | * |
| 22 | */ | 21 | */ |
| 23 | 22 | ||
| 24 | #include "busybox.h" | ||
| 25 | #include <signal.h> | 23 | #include <signal.h> |
| 24 | #include <stdlib.h> | ||
| 25 | #include <unistd.h> | ||
| 26 | #include <getopt.h> | ||
| 27 | #include <sys/reboot.h> | ||
| 28 | #include "busybox.h" | ||
| 26 | #include "init_shared.h" | 29 | #include "init_shared.h" |
| 27 | 30 | ||
| 28 | 31 | ||
| 29 | extern int halt_main(int argc, char **argv) | 32 | extern int halt_main(int argc, char **argv) |
| 30 | { | 33 | { |
| 34 | char *delay; /* delay in seconds before rebooting */ | ||
| 35 | |||
| 36 | if(bb_getopt_ulflags(argc, argv, "d:", &delay)) { | ||
| 37 | sleep(atoi(delay)); | ||
| 38 | } | ||
| 39 | |||
| 40 | #ifndef CONFIG_INIT | ||
| 41 | #ifndef RB_HALT_SYSTEM | ||
| 42 | #define RB_HALT_SYSTEM 0xcdef0123 | ||
| 43 | #endif | ||
| 44 | return(bb_shutdown_system(RB_HALT_SYSTEM)); | ||
| 45 | #else | ||
| 31 | return kill_init(SIGUSR1); | 46 | return kill_init(SIGUSR1); |
| 47 | #endif | ||
| 32 | } | 48 | } |
diff --git a/init/init_shared.c b/init/init_shared.c index 842942fe3..81e1ea056 100644 --- a/init/init_shared.c +++ b/init/init_shared.c | |||
| @@ -1,9 +1,35 @@ | |||
| 1 | /* vi: set sw=4 ts=4: */ | ||
| 2 | /* | ||
| 3 | * Stuff shared between init, reboot, halt, and poweroff | ||
| 4 | * | ||
| 5 | * Copyright (C) 1999-2003 by Erik Andersen <andersen@codepoet.org> | ||
| 6 | * | ||
| 7 | * This program is free software; you can redistribute it and/or modify | ||
| 8 | * it under the terms of the GNU General Public License as published by | ||
| 9 | * the Free Software Foundation; either version 2 of the License, or | ||
| 10 | * (at your option) any later version. | ||
| 11 | * | ||
| 12 | * This program is distributed in the hope that it will be useful, | ||
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 15 | * General Public License for more details. | ||
| 16 | * | ||
| 17 | * You should have received a copy of the GNU General Public License | ||
| 18 | * along with this program; if not, write to the Free Software | ||
| 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
| 20 | * | ||
| 21 | */ | ||
| 22 | |||
| 1 | #include <signal.h> | 23 | #include <signal.h> |
| 24 | #include <stdlib.h> | ||
| 25 | #include <unistd.h> | ||
| 26 | #include <getopt.h> | ||
| 27 | #include <sys/reboot.h> | ||
| 28 | #include <sys/reboot.h> | ||
| 29 | #include <sys/syslog.h> | ||
| 2 | #include "busybox.h" | 30 | #include "busybox.h" |
| 3 | |||
| 4 | #include "init_shared.h" | 31 | #include "init_shared.h" |
| 5 | 32 | ||
| 6 | |||
| 7 | extern int kill_init(int sig) | 33 | extern int kill_init(int sig) |
| 8 | { | 34 | { |
| 9 | #ifdef CONFIG_FEATURE_INITRD | 35 | #ifdef CONFIG_FEATURE_INITRD |
| @@ -19,3 +45,54 @@ extern int kill_init(int sig) | |||
| 19 | return(kill(1, sig)); | 45 | return(kill(1, sig)); |
| 20 | #endif | 46 | #endif |
| 21 | } | 47 | } |
| 48 | |||
| 49 | #ifndef CONFIG_INIT | ||
| 50 | #define LOG 0x1 | ||
| 51 | #define CONSOLE 0x2 | ||
| 52 | extern int bb_shutdown_system(unsigned long magic) | ||
| 53 | { | ||
| 54 | int pri = LOG_KERN|LOG_NOTICE|LOG_FACMASK; | ||
| 55 | char *message; | ||
| 56 | |||
| 57 | /* Don't kill ourself */ | ||
| 58 | signal(SIGTERM,SIG_IGN); | ||
| 59 | signal(SIGHUP,SIG_IGN); | ||
| 60 | setpgrp(); | ||
| 61 | |||
| 62 | /* Allow Ctrl-Alt-Del to reboot system. */ | ||
| 63 | #ifndef RB_ENABLE_CAD | ||
| 64 | #define RB_ENABLE_CAD 0x89abcdef | ||
| 65 | #endif | ||
| 66 | reboot(RB_ENABLE_CAD); | ||
| 67 | |||
| 68 | openlog("shutdown", 0, pri); | ||
| 69 | |||
| 70 | message = "\n\rThe system is going down NOW !!\n"; | ||
| 71 | syslog(pri, "%s", message); | ||
| 72 | fprintf(stdout, "%s", message); | ||
| 73 | |||
| 74 | sync(); | ||
| 75 | |||
| 76 | /* Send signals to every process _except_ pid 1 */ | ||
| 77 | message = "\rSending SIGTERM to all processes.\n"; | ||
| 78 | syslog(pri, "%s", message); | ||
| 79 | fprintf(stdout, "%s", message); | ||
| 80 | |||
| 81 | kill(-1, SIGTERM); | ||
| 82 | sleep(1); | ||
| 83 | sync(); | ||
| 84 | |||
| 85 | message = "\rSending SIGKILL to all processes.\n"; | ||
| 86 | syslog(pri, "%s", message); | ||
| 87 | fprintf(stdout, "%s", message); | ||
| 88 | |||
| 89 | kill(-1, SIGKILL); | ||
| 90 | sleep(1); | ||
| 91 | |||
| 92 | sync(); | ||
| 93 | |||
| 94 | reboot(magic); | ||
| 95 | return 0; /* Shrug */ | ||
| 96 | } | ||
| 97 | #endif | ||
| 98 | |||
diff --git a/init/init_shared.h b/init/init_shared.h index d10a1bd3b..1e4cfac98 100644 --- a/init/init_shared.h +++ b/init/init_shared.h | |||
| @@ -1 +1,3 @@ | |||
| 1 | extern int kill_init(int sig); | 1 | extern int kill_init(int sig); |
| 2 | extern int bb_shutdown_system(unsigned long magic); | ||
| 3 | |||
diff --git a/init/poweroff.c b/init/poweroff.c index d630aa6c2..e5d45dfa0 100644 --- a/init/poweroff.c +++ b/init/poweroff.c | |||
| @@ -2,7 +2,6 @@ | |||
| 2 | /* | 2 | /* |
| 3 | * Mini poweroff implementation for busybox | 3 | * Mini poweroff implementation for busybox |
| 4 | * | 4 | * |
| 5 | * Copyright (C) 1995, 1996 by Bruce Perens <bruce@pixar.com>. | ||
| 6 | * Copyright (C) 1999-2003 by Erik Andersen <andersen@codepoet.org> | 5 | * Copyright (C) 1999-2003 by Erik Andersen <andersen@codepoet.org> |
| 7 | * | 6 | * |
| 8 | * This program is free software; you can redistribute it and/or modify | 7 | * This program is free software; you can redistribute it and/or modify |
| @@ -21,10 +20,37 @@ | |||
| 21 | * | 20 | * |
| 22 | */ | 21 | */ |
| 23 | 22 | ||
| 24 | #include "busybox.h" | ||
| 25 | #include <signal.h> | 23 | #include <signal.h> |
| 24 | #include <stdlib.h> | ||
| 25 | #include <unistd.h> | ||
| 26 | #include <getopt.h> | ||
| 27 | #include <sys/reboot.h> | ||
| 28 | #include "busybox.h" | ||
| 29 | #include "init_shared.h" | ||
| 30 | |||
| 26 | 31 | ||
| 27 | extern int poweroff_main(int argc, char **argv) | 32 | extern int poweroff_main(int argc, char **argv) |
| 28 | { | 33 | { |
| 34 | char *delay; /* delay in seconds before rebooting */ | ||
| 35 | |||
| 36 | if(bb_getopt_ulflags(argc, argv, "d:", &delay)) { | ||
| 37 | sleep(atoi(delay)); | ||
| 38 | } | ||
| 39 | |||
| 40 | #ifndef CONFIG_INIT | ||
| 41 | #ifndef RB_POWER_OFF | ||
| 42 | #define RB_POWER_OFF 0x4321fedc | ||
| 43 | #endif | ||
| 44 | return(bb_shutdown_system(RB_POWER_OFF)); | ||
| 45 | #else | ||
| 29 | return kill_init(SIGUSR2); | 46 | return kill_init(SIGUSR2); |
| 47 | #endif | ||
| 30 | } | 48 | } |
| 49 | |||
| 50 | /* | ||
| 51 | Local Variables: | ||
| 52 | c-file-style: "linux" | ||
| 53 | c-basic-offset: 4 | ||
| 54 | tab-width: 4 | ||
| 55 | End: | ||
| 56 | */ | ||
diff --git a/init/reboot.c b/init/reboot.c index 5ca8b588a..a3c0000f1 100644 --- a/init/reboot.c +++ b/init/reboot.c | |||
| @@ -2,7 +2,6 @@ | |||
| 2 | /* | 2 | /* |
| 3 | * Mini reboot implementation for busybox | 3 | * Mini reboot implementation for busybox |
| 4 | * | 4 | * |
| 5 | * Copyright (C) 1995, 1996 by Bruce Perens <bruce@pixar.com>. | ||
| 6 | * Copyright (C) 1999-2003 by Erik Andersen <andersen@codepoet.org> | 5 | * Copyright (C) 1999-2003 by Erik Andersen <andersen@codepoet.org> |
| 7 | * | 6 | * |
| 8 | * This program is free software; you can redistribute it and/or modify | 7 | * This program is free software; you can redistribute it and/or modify |
| @@ -30,11 +29,6 @@ | |||
| 30 | #include "init_shared.h" | 29 | #include "init_shared.h" |
| 31 | 30 | ||
| 32 | 31 | ||
| 33 | #ifndef RB_ENABLE_CAD | ||
| 34 | static const int RB_ENABLE_CAD = 0x89abcdef; | ||
| 35 | static const int RB_AUTOBOOT = 0x01234567; | ||
| 36 | #endif | ||
| 37 | |||
| 38 | extern int reboot_main(int argc, char **argv) | 32 | extern int reboot_main(int argc, char **argv) |
| 39 | { | 33 | { |
| 40 | char *delay; /* delay in seconds before rebooting */ | 34 | char *delay; /* delay in seconds before rebooting */ |
| @@ -43,34 +37,13 @@ extern int reboot_main(int argc, char **argv) | |||
| 43 | sleep(atoi(delay)); | 37 | sleep(atoi(delay)); |
| 44 | } | 38 | } |
| 45 | 39 | ||
| 46 | #ifdef CONFIG_USER_INIT | 40 | #ifndef CONFIG_INIT |
| 47 | /* Don't kill ourself */ | 41 | #ifndef RB_AUTOBOOT |
| 48 | signal(SIGTERM,SIG_IGN); | 42 | #define RB_AUTOBOOT 0x01234567 |
| 49 | signal(SIGHUP,SIG_IGN); | 43 | #endif |
| 50 | setpgrp(); | 44 | return(bb_shutdown_system(RB_AUTOBOOT)); |
| 51 | |||
| 52 | /* Allow Ctrl-Alt-Del to reboot system. */ | ||
| 53 | reboot(RB_ENABLE_CAD); | ||
| 54 | |||
| 55 | message(CONSOLE|LOG, "\n\rThe system is going down NOW !!\n"); | ||
| 56 | sync(); | ||
| 57 | |||
| 58 | /* Send signals to every process _except_ pid 1 */ | ||
| 59 | message(CONSOLE|LOG, "\rSending SIGTERM to all processes.\n"); | ||
| 60 | kill(-1, SIGTERM); | ||
| 61 | sleep(1); | ||
| 62 | sync(); | ||
| 63 | |||
| 64 | message(CONSOLE|LOG, "\rSending SIGKILL to all processes.\n"); | ||
| 65 | kill(-1, SIGKILL); | ||
| 66 | sleep(1); | ||
| 67 | |||
| 68 | sync(); | ||
| 69 | |||
| 70 | reboot(RB_AUTOBOOT); | ||
| 71 | return 0; /* Shrug */ | ||
| 72 | #else | 45 | #else |
| 73 | return kill_init(SIGTERM); | 46 | return kill_init(SIGUSR2); |
| 74 | #endif | 47 | #endif |
| 75 | } | 48 | } |
| 76 | 49 | ||
