aboutsummaryrefslogtreecommitdiff
path: root/busybox/init/init_shared.c
diff options
context:
space:
mode:
Diffstat (limited to 'busybox/init/init_shared.c')
-rw-r--r--busybox/init/init_shared.c95
1 files changed, 95 insertions, 0 deletions
diff --git a/busybox/init/init_shared.c b/busybox/init/init_shared.c
new file mode 100644
index 000000000..0ad55a433
--- /dev/null
+++ b/busybox/init/init_shared.c
@@ -0,0 +1,95 @@
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 * 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
23#include <signal.h>
24#include <stdlib.h>
25#include <unistd.h>
26#include <getopt.h>
27#include <sys/reboot.h>
28#include <sys/syslog.h>
29#include "busybox.h"
30#include "init_shared.h"
31
32extern int kill_init(int sig)
33{
34#ifdef CONFIG_FEATURE_INITRD
35 /* don't assume init's pid == 1 */
36 long *pid = find_pid_by_name("init");
37 if (!pid || *pid<=0) {
38 pid = find_pid_by_name("linuxrc");
39 if (!pid || *pid<=0)
40 bb_error_msg_and_die("no process killed");
41 }
42 return(kill(*pid, sig));
43#else
44 return(kill(1, sig));
45#endif
46}
47
48#ifndef CONFIG_INIT
49const char * const bb_shutdown_format = "\r%s\n";
50extern int bb_shutdown_system(unsigned long magic)
51{
52 int pri = LOG_KERN|LOG_NOTICE|LOG_FACMASK;
53 const char *message;
54
55 /* Don't kill ourself */
56 signal(SIGTERM,SIG_IGN);
57 signal(SIGHUP,SIG_IGN);
58 setpgrp();
59
60 /* Allow Ctrl-Alt-Del to reboot system. */
61#ifndef RB_ENABLE_CAD
62#define RB_ENABLE_CAD 0x89abcdef
63#endif
64 reboot(RB_ENABLE_CAD);
65
66 openlog(bb_applet_name, 0, pri);
67
68 message = "\nThe system is going down NOW !!";
69 syslog(pri, "%s", message);
70 printf(bb_shutdown_format, message);
71
72 sync();
73
74 /* Send signals to every process _except_ pid 1 */
75 message = "Sending SIGTERM to all processes.";
76 syslog(pri, "%s", message);
77 printf(bb_shutdown_format, message);
78
79 kill(-1, SIGTERM);
80 sleep(1);
81 sync();
82
83 message = "Sending SIGKILL to all processes.";
84 syslog(pri, "%s", message);
85 printf(bb_shutdown_format, message);
86
87 kill(-1, SIGKILL);
88 sleep(1);
89
90 sync();
91
92 reboot(magic);
93 return 0; /* Shrug */
94}
95#endif