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-01-22 02:41:51 +00:00
|
|
|
* Licensed under GPLv2 or later, 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-06-27 17:08:15 +00:00
|
|
|
#include <signal.h>
|
2003-07-22 09:41:39 +00:00
|
|
|
#include <stdlib.h>
|
2006-05-26 14:24:56 +00:00
|
|
|
#include <sys/types.h>
|
2003-07-22 09:41:39 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <getopt.h>
|
|
|
|
#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
|
|
|
|
2003-07-22 17:14:10 +00:00
|
|
|
openlog(bb_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
|