1 /* vi: set sw=4 ts=4: */
3 * Stuff shared between init, reboot, halt, and poweroff
5 * Copyright (C) 1999-2003 by Erik Andersen <andersen@codepoet.org>
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.
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.
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
27 #include <sys/reboot.h>
28 #include <sys/reboot.h>
29 #include <sys/syslog.h>
31 #include "init_shared.h"
33 extern int kill_init(int sig)
35 #ifdef CONFIG_FEATURE_INITRD
36 /* don't assume init's pid == 1 */
37 long *pid = find_pid_by_name("init");
38 if (!pid || *pid<=0) {
39 pid = find_pid_by_name("linuxrc");
41 bb_error_msg_and_die("no process killed");
43 return(kill(*pid, sig));
50 const char * const bb_shutdown_format = "\r%s\n";
51 extern int bb_shutdown_system(unsigned long magic)
53 int pri = LOG_KERN|LOG_NOTICE|LOG_FACMASK;
56 /* Don't kill ourself */
57 signal(SIGTERM,SIG_IGN);
58 signal(SIGHUP,SIG_IGN);
61 /* Allow Ctrl-Alt-Del to reboot system. */
63 #define RB_ENABLE_CAD 0x89abcdef
65 reboot(RB_ENABLE_CAD);
67 openlog(bb_applet_name, 0, pri);
69 message = "\nThe system is going down NOW !!";
70 syslog(pri, "%s", message);
71 printf(bb_shutdown_format, message);
75 /* Send signals to every process _except_ pid 1 */
76 message = "Sending SIGTERM to all processes.";
77 syslog(pri, "%s", message);
78 printf(bb_shutdown_format, message);
84 message = "Sending SIGKILL to all processes.";
85 syslog(pri, "%s", message);
86 printf(bb_shutdown_format, message);