diff options
author | Eric Andersen <andersen@codepoet.org> | 2003-07-22 09:41:39 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2003-07-22 09:41:39 +0000 |
commit | 0246222351a8787e2e726c2526d795440893859c (patch) | |
tree | a254319c3697e8f1493373cd1148a6aa1e74a6a6 /init/init_shared.c | |
parent | 85e5e72bc1acd9d58c11bde6e14c8270cd9f169f (diff) | |
download | busybox-w32-0246222351a8787e2e726c2526d795440893859c.tar.gz busybox-w32-0246222351a8787e2e726c2526d795440893859c.tar.bz2 busybox-w32-0246222351a8787e2e726c2526d795440893859c.zip |
Support reboot, halt, and poweroff independent of busybox init.
Simplify and fixup some logic.
-Erik
Diffstat (limited to 'init/init_shared.c')
-rw-r--r-- | init/init_shared.c | 81 |
1 files changed, 79 insertions, 2 deletions
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 | |||