Update a bunch of docs. Run a script to update my email addr.
[oweals/busybox.git] / init / reboot.c
1 /* vi: set sw=4 ts=4: */
2 /*
3  * Mini reboot implementation for busybox
4  *
5  * Copyright (C) 1995, 1996 by Bruce Perens <bruce@pixar.com>.
6  * Copyright (C) 1999-2003 by Erik Andersen <andersen@codepoet.org>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21  *
22  */
23
24 #include <signal.h>
25 #include <stdlib.h>
26 #include <unistd.h>
27 #include <getopt.h>
28
29 #include "busybox.h"
30 #include "init_shared.h"
31
32
33 #if (__GNU_LIBRARY__ > 5) || defined(__dietlibc__) 
34   #include <sys/reboot.h>
35   #define init_reboot(magic) reboot(magic)
36 #else
37   #define init_reboot(magic) reboot(0xfee1dead, 672274793, magic)
38 #endif
39
40 #ifndef RB_ENABLE_CAD
41 static const int RB_ENABLE_CAD = 0x89abcdef;
42 static const int RB_AUTOBOOT = 0x01234567;
43 #endif
44
45 extern int reboot_main(int argc, char **argv)
46 {
47         char *delay; /* delay in seconds before rebooting */
48
49         if(bb_getopt_ulflags(argc, argv, "d:", &delay)) {
50                 sleep(atoi(delay));
51         }
52
53 #ifdef CONFIG_USER_INIT
54                 /* Don't kill ourself */
55         signal(SIGTERM,SIG_IGN);
56         signal(SIGHUP,SIG_IGN);
57         setpgrp();
58
59                 /* Allow Ctrl-Alt-Del to reboot system. */
60                 init_reboot(RB_ENABLE_CAD);
61
62                 message(CONSOLE|LOG, "\n\rThe system is going down NOW !!\n");
63                 sync();
64
65                 /* Send signals to every process _except_ pid 1 */
66                 message(CONSOLE|LOG, "\rSending SIGTERM to all processes.\n");
67                 kill(-1, SIGTERM);
68                 sleep(1);
69                 sync();
70
71                 message(CONSOLE|LOG, "\rSending SIGKILL to all processes.\n");
72                 kill(-1, SIGKILL);
73                 sleep(1);
74
75                 sync();
76
77                 init_reboot(RB_AUTOBOOT);
78                 return 0; /* Shrug */
79 #else
80         return kill_init(SIGTERM);
81 #endif
82 }
83
84 /*
85 Local Variables:
86 c-file-style: "linux"
87 c-basic-offset: 4
88 tab-width: 4
89 End:
90 */