aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorandersen <andersen@69ca8d6d-28ef-0310-b511-8ec308f3f277>2002-09-17 08:40:12 +0000
committerandersen <andersen@69ca8d6d-28ef-0310-b511-8ec308f3f277>2002-09-17 08:40:12 +0000
commit21cb04abdd3138bbc0f34c76327bd09c8f7b213a (patch)
tree61011987abbe67c8aa7f4ebeba570a1c67ac01ce
parentd093ec17858d3e43afb2874fc1b9077b88de32ec (diff)
downloadbusybox-w32-21cb04abdd3138bbc0f34c76327bd09c8f7b213a.tar.gz
busybox-w32-21cb04abdd3138bbc0f34c76327bd09c8f7b213a.tar.bz2
busybox-w32-21cb04abdd3138bbc0f34c76327bd09c8f7b213a.zip
Patch from David McCullough <davidm@snapgear.com>
git-svn-id: svn://busybox.net/trunk/busybox@5535 69ca8d6d-28ef-0310-b511-8ec308f3f277
-rw-r--r--init/reboot.c77
1 files changed, 72 insertions, 5 deletions
diff --git a/init/reboot.c b/init/reboot.c
index 001a3c7d2..1c9eedde5 100644
--- a/init/reboot.c
+++ b/init/reboot.c
@@ -23,21 +23,88 @@
23 23
24#include "busybox.h" 24#include "busybox.h"
25#include <signal.h> 25#include <signal.h>
26#include <stdlib.h>
27#include <unistd.h>
28#include <getopt.h>
29
30#if (__GNU_LIBRARY__ > 5) || defined(__dietlibc__)
31 #include <sys/reboot.h>
32 #define init_reboot(magic) reboot(magic)
33#else
34 #define init_reboot(magic) reboot(0xfee1dead, 672274793, magic)
35#endif
36#ifndef RB_ENABLE_CAD
37static const int RB_ENABLE_CAD = 0x89abcdef;
38static const int RB_AUTOBOOT = 0x01234567;
39#endif
26 40
27extern int reboot_main(int argc, char **argv) 41extern int reboot_main(int argc, char **argv)
28{ 42{
43 int delay = 0; /* delay in seconds before rebooting */
44 int rc;
45
46 while ((rc = getopt(argc, argv, "d:")) > 0) {
47 switch (rc) {
48 case 'd':
49 delay = atoi(optarg);
50 break;
51
52 default:
53 show_usage();
54 break;
55 }
56 }
57
58 if(delay > 0)
59 sleep(delay);
60
61#ifdef CONFIG_USER_INIT
62 /* Don't kill ourself */
63 signal(SIGTERM,SIG_IGN);
64 signal(SIGHUP,SIG_IGN);
65 setpgrp();
66
67 /* Allow Ctrl-Alt-Del to reboot system. */
68 init_reboot(RB_ENABLE_CAD);
69
70 message(CONSOLE|LOG, "\n\rThe system is going down NOW !!\n");
71 sync();
72
73 /* Send signals to every process _except_ pid 1 */
74 message(CONSOLE|LOG, "\rSending SIGTERM to all processes.\n");
75 kill(-1, SIGTERM);
76 sleep(1);
77 sync();
78
79 message(CONSOLE|LOG, "\rSending SIGKILL to all processes.\n");
80 kill(-1, SIGKILL);
81 sleep(1);
82
83 sync();
84 if (kernelVersion > 0 && kernelVersion <= KERNEL_VERSION(2,2,11)) {
85 /* bdflush, kupdate not needed for kernels >2.2.11 */
86 bdflush(1, 0);
87 sync();
88 }
89
90 init_reboot(RB_AUTOBOOT);
91 exit(0); /* Shrug */
92#else
29#ifdef CONFIG_FEATURE_INITRD 93#ifdef CONFIG_FEATURE_INITRD
30 /* don't assume init's pid == 1 */ 94 {
31 long *pid = find_pid_by_name("init"); 95 /* don't assume init's pid == 1 */
32 if (!pid || *pid<=0) { 96 long *pid = find_pid_by_name("init");
33 pid = find_pid_by_name("linuxrc"); 97 if (!pid || *pid<=0)
98 pid = find_pid_by_name("linuxrc");
34 if (!pid || *pid<=0) 99 if (!pid || *pid<=0)
35 error_msg_and_die("no process killed"); 100 error_msg_and_die("no process killed");
101 fflush(stdout);
102 return(kill(*pid, SIGTERM));
36 } 103 }
37 return(kill(*pid, SIGTERM));
38#else 104#else
39 return(kill(1, SIGTERM)); 105 return(kill(1, SIGTERM));
40#endif 106#endif
107#endif
41} 108}
42 109
43/* 110/*