2003-07-22 09:41:39 +00:00
|
|
|
/* vi: set sw=4 ts=4: */
|
|
|
|
/*
|
|
|
|
* Stuff shared between init, reboot, halt, and poweroff
|
|
|
|
*
|
2004-03-15 08:29:22 +00:00
|
|
|
* Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
|
2003-07-22 09:41:39 +00:00
|
|
|
*
|
2006-09-22 02:52:41 +00:00
|
|
|
* Licensed under GPL version 2, see file LICENSE in this tarball for details.
|
2003-07-22 09:41:39 +00:00
|
|
|
*/
|
|
|
|
|
2006-06-02 20:56:16 +00:00
|
|
|
#include "busybox.h"
|
2003-07-22 09:41:39 +00:00
|
|
|
#include <sys/reboot.h>
|
|
|
|
#include <sys/syslog.h>
|
2003-06-27 17:08:15 +00:00
|
|
|
#include "init_shared.h"
|
|
|
|
|
2006-05-31 18:57:56 +00:00
|
|
|
const char * const init_sending_format = "Sending SIG%s to all processes.";
|
2003-07-22 09:41:39 +00:00
|
|
|
#ifndef CONFIG_INIT
|
2003-07-22 17:14:10 +00:00
|
|
|
const char * const bb_shutdown_format = "\r%s\n";
|
2006-03-06 20:47:33 +00:00
|
|
|
int bb_shutdown_system(unsigned long magic)
|
2003-07-22 09:41:39 +00:00
|
|
|
{
|
|
|
|
int pri = LOG_KERN|LOG_NOTICE|LOG_FACMASK;
|
2003-07-22 17:14:10 +00:00
|
|
|
const char *message;
|
2003-07-22 09:41:39 +00:00
|
|
|
|
2003-07-22 17:14:10 +00:00
|
|
|
/* Don't kill ourself */
|
|
|
|
signal(SIGTERM,SIG_IGN);
|
|
|
|
signal(SIGHUP,SIG_IGN);
|
2006-05-26 14:24:56 +00:00
|
|
|
bb_setpgrp;
|
2003-07-22 09:41:39 +00:00
|
|
|
|
2003-07-22 17:14:10 +00:00
|
|
|
/* Allow Ctrl-Alt-Del to reboot system. */
|
2003-07-22 09:41:39 +00:00
|
|
|
#ifndef RB_ENABLE_CAD
|
|
|
|
#define RB_ENABLE_CAD 0x89abcdef
|
|
|
|
#endif
|
2003-07-22 17:14:10 +00:00
|
|
|
reboot(RB_ENABLE_CAD);
|
2003-07-22 09:41:39 +00:00
|
|
|
|
2006-10-03 21:00:43 +00:00
|
|
|
openlog(applet_name, 0, pri);
|
2003-07-22 09:41:39 +00:00
|
|
|
|
2003-07-22 17:14:10 +00:00
|
|
|
message = "\nThe system is going down NOW !!";
|
2003-07-22 09:41:39 +00:00
|
|
|
syslog(pri, "%s", message);
|
2003-07-22 17:14:10 +00:00
|
|
|
printf(bb_shutdown_format, message);
|
2003-07-22 09:41:39 +00:00
|
|
|
|
2003-07-22 17:14:10 +00:00
|
|
|
sync();
|
2003-07-22 09:41:39 +00:00
|
|
|
|
2003-07-22 17:14:10 +00:00
|
|
|
/* Send signals to every process _except_ pid 1 */
|
2006-05-30 18:17:21 +00:00
|
|
|
message = "TERM";
|
|
|
|
syslog(pri, init_sending_format, message);
|
2003-07-22 17:14:10 +00:00
|
|
|
printf(bb_shutdown_format, message);
|
2003-07-22 09:41:39 +00:00
|
|
|
|
2003-07-22 17:14:10 +00:00
|
|
|
kill(-1, SIGTERM);
|
|
|
|
sleep(1);
|
|
|
|
sync();
|
2003-07-22 09:41:39 +00:00
|
|
|
|
2006-05-30 18:17:21 +00:00
|
|
|
message = "KILL";
|
|
|
|
syslog(pri, init_sending_format, message);
|
2003-07-22 17:14:10 +00:00
|
|
|
printf(bb_shutdown_format, message);
|
2003-07-22 09:41:39 +00:00
|
|
|
|
2003-07-22 17:14:10 +00:00
|
|
|
kill(-1, SIGKILL);
|
|
|
|
sleep(1);
|
2003-07-22 09:41:39 +00:00
|
|
|
|
2003-07-22 17:14:10 +00:00
|
|
|
sync();
|
2003-07-22 09:41:39 +00:00
|
|
|
|
2003-07-22 17:14:10 +00:00
|
|
|
reboot(magic);
|
|
|
|
return 0; /* Shrug */
|
2003-07-22 09:41:39 +00:00
|
|
|
}
|
|
|
|
#endif
|