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