Remove remaining libc5 support code
[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 #include <sys/reboot.h>
29 #include "busybox.h"
30 #include "init_shared.h"
31
32
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)
39 {
40         char *delay; /* delay in seconds before rebooting */
41
42         if(bb_getopt_ulflags(argc, argv, "d:", &delay)) {
43                 sleep(atoi(delay));
44         }
45
46 #ifdef CONFIG_USER_INIT
47                 /* Don't kill ourself */
48         signal(SIGTERM,SIG_IGN);
49         signal(SIGHUP,SIG_IGN);
50         setpgrp();
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
73         return kill_init(SIGTERM);
74 #endif
75 }
76
77 /*
78 Local Variables:
79 c-file-style: "linux"
80 c-basic-offset: 4
81 tab-width: 4
82 End:
83 */