summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--init/Config.in9
-rw-r--r--init/halt.c20
-rw-r--r--init/init_shared.c81
-rw-r--r--init/init_shared.h2
-rw-r--r--init/poweroff.c30
-rw-r--r--init/reboot.c39
6 files changed, 136 insertions, 45 deletions
diff --git a/init/Config.in b/init/Config.in
index c8c6a9c..af7aac8 100644
--- a/init/Config.in
+++ b/init/Config.in
@@ -27,7 +27,7 @@ config CONFIG_FEATURE_INITRD
config CONFIG_FEATURE_INIT_COREDUMPS
bool " Support dumping core for child processes (debugging only)?"
- default y
+ default n
depends on CONFIG_INIT
help
If this option is enabled and the file /.init_enable_core
@@ -43,31 +43,28 @@ config CONFIG_FEATURE_EXTRA_QUIET
Prevent init from logging some messages to the console
during boot.
-# Some apps that are meaningless without BusyBox running as init
config CONFIG_HALT
bool "halt"
default y
- depends on CONFIG_INIT
help
- 'halt' tells the kernel to stop all processes and halt the system.
+ Stop all processes and halt the system.
config CONFIG_POWEROFF
bool "poweroff"
default y
- depends on CONFIG_INIT
help
Stop all processes and (try to) power off the system.
config CONFIG_REBOOT
bool "reboot"
default y
- depends on CONFIG_INIT
help
Stop all processes and reboot the system.
config CONFIG_MINIT
bool "minit"
default n
+ depends on ! CONFIG_INIT
help
Minimal init, based on minit v0.9.1. This is a simple
init replacement that handles starting/stopping services,
diff --git a/init/halt.c b/init/halt.c
index 10f16c7..decdaea 100644
--- a/init/halt.c
+++ b/init/halt.c
@@ -2,7 +2,6 @@
/*
* Mini halt implementation for busybox
*
- * Copyright (C) 1995, 1996 by Bruce Perens <bruce@pixar.com>.
* Copyright (C) 1999-2003 by Erik Andersen <andersen@codepoet.org>
*
* This program is free software; you can redistribute it and/or modify
@@ -21,12 +20,29 @@
*
*/
-#include "busybox.h"
#include <signal.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <getopt.h>
+#include <sys/reboot.h>
+#include "busybox.h"
#include "init_shared.h"
extern int halt_main(int argc, char **argv)
{
+ char *delay; /* delay in seconds before rebooting */
+
+ if(bb_getopt_ulflags(argc, argv, "d:", &delay)) {
+ sleep(atoi(delay));
+ }
+
+#ifndef CONFIG_INIT
+#ifndef RB_HALT_SYSTEM
+#define RB_HALT_SYSTEM 0xcdef0123
+#endif
+ return(bb_shutdown_system(RB_HALT_SYSTEM));
+#else
return kill_init(SIGUSR1);
+#endif
}
diff --git a/init/init_shared.c b/init/init_shared.c
index 842942f..81e1ea0 100644
--- a/init/init_shared.c
+++ b/init/init_shared.c
@@ -1,9 +1,35 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * Stuff shared between init, reboot, halt, and poweroff
+ *
+ * Copyright (C) 1999-2003 by Erik Andersen <andersen@codepoet.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
#include <signal.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <getopt.h>
+#include <sys/reboot.h>
+#include <sys/reboot.h>
+#include <sys/syslog.h>
#include "busybox.h"
-
#include "init_shared.h"
-
extern int kill_init(int sig)
{
#ifdef CONFIG_FEATURE_INITRD
@@ -19,3 +45,54 @@ extern int kill_init(int sig)
return(kill(1, sig));
#endif
}
+
+#ifndef CONFIG_INIT
+#define LOG 0x1
+#define CONSOLE 0x2
+extern int bb_shutdown_system(unsigned long magic)
+{
+ int pri = LOG_KERN|LOG_NOTICE|LOG_FACMASK;
+ char *message;
+
+ /* Don't kill ourself */
+ signal(SIGTERM,SIG_IGN);
+ signal(SIGHUP,SIG_IGN);
+ setpgrp();
+
+ /* Allow Ctrl-Alt-Del to reboot system. */
+#ifndef RB_ENABLE_CAD
+#define RB_ENABLE_CAD 0x89abcdef
+#endif
+ reboot(RB_ENABLE_CAD);
+
+ openlog("shutdown", 0, pri);
+
+ message = "\n\rThe system is going down NOW !!\n";
+ syslog(pri, "%s", message);
+ fprintf(stdout, "%s", message);
+
+ sync();
+
+ /* Send signals to every process _except_ pid 1 */
+ message = "\rSending SIGTERM to all processes.\n";
+ syslog(pri, "%s", message);
+ fprintf(stdout, "%s", message);
+
+ kill(-1, SIGTERM);
+ sleep(1);
+ sync();
+
+ message = "\rSending SIGKILL to all processes.\n";
+ syslog(pri, "%s", message);
+ fprintf(stdout, "%s", message);
+
+ kill(-1, SIGKILL);
+ sleep(1);
+
+ sync();
+
+ reboot(magic);
+ return 0; /* Shrug */
+}
+#endif
+
diff --git a/init/init_shared.h b/init/init_shared.h
index d10a1bd..1e4cfac 100644
--- a/init/init_shared.h
+++ b/init/init_shared.h
@@ -1 +1,3 @@
extern int kill_init(int sig);
+extern int bb_shutdown_system(unsigned long magic);
+
diff --git a/init/poweroff.c b/init/poweroff.c
index d630aa6..e5d45df 100644
--- a/init/poweroff.c
+++ b/init/poweroff.c
@@ -2,7 +2,6 @@
/*
* Mini poweroff implementation for busybox
*
- * Copyright (C) 1995, 1996 by Bruce Perens <bruce@pixar.com>.
* Copyright (C) 1999-2003 by Erik Andersen <andersen@codepoet.org>
*
* This program is free software; you can redistribute it and/or modify
@@ -21,10 +20,37 @@
*
*/
-#include "busybox.h"
#include <signal.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <getopt.h>
+#include <sys/reboot.h>
+#include "busybox.h"
+#include "init_shared.h"
+
extern int poweroff_main(int argc, char **argv)
{
+ char *delay; /* delay in seconds before rebooting */
+
+ if(bb_getopt_ulflags(argc, argv, "d:", &delay)) {
+ sleep(atoi(delay));
+ }
+
+#ifndef CONFIG_INIT
+#ifndef RB_POWER_OFF
+#define RB_POWER_OFF 0x4321fedc
+#endif
+ return(bb_shutdown_system(RB_POWER_OFF));
+#else
return kill_init(SIGUSR2);
+#endif
}
+
+/*
+Local Variables:
+c-file-style: "linux"
+c-basic-offset: 4
+tab-width: 4
+End:
+*/
diff --git a/init/reboot.c b/init/reboot.c
index 5ca8b58..a3c0000 100644
--- a/init/reboot.c
+++ b/init/reboot.c
@@ -2,7 +2,6 @@
/*
* Mini reboot implementation for busybox
*
- * Copyright (C) 1995, 1996 by Bruce Perens <bruce@pixar.com>.
* Copyright (C) 1999-2003 by Erik Andersen <andersen@codepoet.org>
*
* This program is free software; you can redistribute it and/or modify
@@ -30,11 +29,6 @@
#include "init_shared.h"
-#ifndef RB_ENABLE_CAD
-static const int RB_ENABLE_CAD = 0x89abcdef;
-static const int RB_AUTOBOOT = 0x01234567;
-#endif
-
extern int reboot_main(int argc, char **argv)
{
char *delay; /* delay in seconds before rebooting */
@@ -43,34 +37,13 @@ extern int reboot_main(int argc, char **argv)
sleep(atoi(delay));
}
-#ifdef CONFIG_USER_INIT
- /* Don't kill ourself */
- signal(SIGTERM,SIG_IGN);
- signal(SIGHUP,SIG_IGN);
- setpgrp();
-
- /* Allow Ctrl-Alt-Del to reboot system. */
- reboot(RB_ENABLE_CAD);
-
- message(CONSOLE|LOG, "\n\rThe system is going down NOW !!\n");
- sync();
-
- /* Send signals to every process _except_ pid 1 */
- message(CONSOLE|LOG, "\rSending SIGTERM to all processes.\n");
- kill(-1, SIGTERM);
- sleep(1);
- sync();
-
- message(CONSOLE|LOG, "\rSending SIGKILL to all processes.\n");
- kill(-1, SIGKILL);
- sleep(1);
-
- sync();
-
- reboot(RB_AUTOBOOT);
- return 0; /* Shrug */
+#ifndef CONFIG_INIT
+#ifndef RB_AUTOBOOT
+#define RB_AUTOBOOT 0x01234567
+#endif
+ return(bb_shutdown_system(RB_AUTOBOOT));
#else
- return kill_init(SIGTERM);
+ return kill_init(SIGUSR2);
#endif
}