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-01-22 08:11:51 +05:30
|
|
|
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
2003-07-22 15:11:39 +05:30
|
|
|
*/
|
|
|
|
|
2003-06-27 22:38:15 +05:30
|
|
|
#include <signal.h>
|
2003-07-22 15:11:39 +05:30
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <getopt.h>
|
|
|
|
#include <sys/reboot.h>
|
|
|
|
#include <sys/syslog.h>
|
2003-06-27 22:38:15 +05:30
|
|
|
#include "busybox.h"
|
|
|
|
#include "init_shared.h"
|
|
|
|
|
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";
|
2003-07-22 15:11:39 +05:30
|
|
|
extern int bb_shutdown_system(unsigned long magic)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
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
|
|
|
|
2003-07-22 22:44:10 +05:30
|
|
|
openlog(bb_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 */
|
|
|
|
message = "Sending SIGTERM to all processes.";
|
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
|
|
|
kill(-1, SIGTERM);
|
|
|
|
sleep(1);
|
|
|
|
sync();
|
2003-07-22 15:11:39 +05:30
|
|
|
|
2003-07-22 22:44:10 +05:30
|
|
|
message = "Sending SIGKILL to all processes.";
|
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
|
|
|
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
|