fix whitespace
[oweals/busybox.git] / init / init_shared.c
1 /* vi: set sw=4 ts=4: */
2 /*
3  * Stuff shared between init, reboot, halt, and poweroff
4  *
5  * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
6  *
7  * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
8  */
9
10 #include <signal.h>
11 #include <stdlib.h>
12 #include <unistd.h>
13 #include <getopt.h>
14 #include <sys/reboot.h>
15 #include <sys/syslog.h>
16 #include "busybox.h"
17 #include "init_shared.h"
18
19 #ifndef CONFIG_INIT
20 const char * const bb_shutdown_format = "\r%s\n";
21 int bb_shutdown_system(unsigned long magic)
22 {
23         int pri = LOG_KERN|LOG_NOTICE|LOG_FACMASK;
24         const char *message;
25
26         /* Don't kill ourself */
27         signal(SIGTERM,SIG_IGN);
28         signal(SIGHUP,SIG_IGN);
29         setpgrp();
30
31         /* Allow Ctrl-Alt-Del to reboot system. */
32 #ifndef RB_ENABLE_CAD
33 #define RB_ENABLE_CAD   0x89abcdef
34 #endif
35         reboot(RB_ENABLE_CAD);
36
37         openlog(bb_applet_name, 0, pri);
38
39         message = "\nThe system is going down NOW !!";
40         syslog(pri, "%s", message);
41         printf(bb_shutdown_format, message);
42
43         sync();
44
45         /* Send signals to every process _except_ pid 1 */
46         message = "Sending SIGTERM to all processes.";
47         syslog(pri, "%s", message);
48         printf(bb_shutdown_format, message);
49
50         kill(-1, SIGTERM);
51         sleep(1);
52         sync();
53
54         message = "Sending SIGKILL to all processes.";
55         syslog(pri, "%s", message);
56         printf(bb_shutdown_format, message);
57
58         kill(-1, SIGKILL);
59         sleep(1);
60
61         sync();
62
63         reboot(magic);
64         return 0; /* Shrug */
65 }
66 #endif