aboutsummaryrefslogtreecommitdiff
path: root/init
diff options
context:
space:
mode:
Diffstat (limited to 'init')
-rw-r--r--init/Config.in55
-rw-r--r--init/halt.c38
-rw-r--r--init/init.c17
-rw-r--r--init/poweroff.c28
-rw-r--r--init/reboot.c28
5 files changed, 56 insertions, 110 deletions
diff --git a/init/Config.in b/init/Config.in
index ba157081c..d5af54e47 100644
--- a/init/Config.in
+++ b/init/Config.in
@@ -12,21 +12,32 @@ config CONFIG_INIT
init is the first program run when the system boots.
config CONFIG_FEATURE_USE_INITTAB
- bool " Support reading an inittab file?"
+ bool " Support reading an inittab file"
default y
depends on CONFIG_INIT
help
Allow init to read an inittab file when the system boot.
-config CONFIG_FEATURE_INITRD
- bool " Support running init from within an initrd?"
+config CONFIG_FEATURE_INIT_SCTTY
+ bool " Support running commands with a controlling-tty"
+ default n
+ depends on CONFIG_INIT
+ help
+ If this option is enabled a command starting with hyphen (-)
+ is run in its own session (setsid(2)) and possibly with a
+ controlling tty (TIOCSCTTY). This is not the traditional init
+ behavour, but is often what you want in an embedded system where
+ the console is only accessed during development or for maintenance.
+
+config CONFIG_FEATURE_EXTRA_QUIET
+ bool " Be _extra_ quiet on boot"
default y
depends on CONFIG_INIT
help
- Allow init to be called from an initrd as linuxrc.
+ Prevent init from logging some messages to the console during boot.
config CONFIG_FEATURE_INIT_COREDUMPS
- bool " Support dumping core for child processes (debugging only)?"
+ bool " Support dumping core for child processes (debugging only)"
default n
depends on CONFIG_INIT
help
@@ -35,30 +46,24 @@ config CONFIG_FEATURE_INIT_COREDUMPS
core file sizes. If this option is disabled, processes
will not generate any core files.
-config CONFIG_FEATURE_INIT_SCTTY
- bool " Support running commands with a controlling-tty?"
- default n
- depends on CONFIG_INIT
- help
- If this option is enabled a command starting with hyphen (-)
- is run in its own session (setsid(2)) and possibly with a
- controlling tty (TIOCSCTTY). This is not the traditional init
- behavour, but is often what you want in an embedded system where
- the console is only accessed during development or for maintenance.
-config CONFIG_FEATURE_EXTRA_QUIET
- bool " Should init be _extra_ quiet on boot?"
+
+config CONFIG_FEATURE_INITRD
+ bool " Support running init from within an initrd (not initramfs)"
default y
depends on CONFIG_INIT
help
- Prevent init from logging some messages to the console
- during boot.
+ Legacy support for running init under the old-style initrd. Allows
+ the name linuxrc to act as init, and it doesn't assume init is PID 1.
+
+ This does not apply to initramfs, which runs /init as PID 1 and
+ requires no special support.
config CONFIG_HALT
- bool "halt"
+ bool "poweroff, halt, and reboot"
default y
help
- Stop all processes and halt the system.
+ Stop all processes and either halt, reboot, or power off the system.
config CONFIG_MESG
bool "mesg"
@@ -67,17 +72,9 @@ config CONFIG_MESG
Mesg controls access to your terminal by others. It is typically
used to allow or disallow other users to write to your terminal
-config CONFIG_POWEROFF
- bool "poweroff"
default y
help
Stop all processes and (try to) power off the system.
-config CONFIG_REBOOT
- bool "reboot"
- default y
- help
- Stop all processes and reboot the system.
-
endmenu
diff --git a/init/halt.c b/init/halt.c
index 89efdd64a..34479742e 100644
--- a/init/halt.c
+++ b/init/halt.c
@@ -1,28 +1,42 @@
/* vi: set sw=4 ts=4: */
/*
- * Mini halt implementation for busybox
+ * Poweroff reboot and halt, oh my.
*
- * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
+ * Copyright 2006 by Rob Landley <rob@landley.net>
*
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
#include <signal.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <getopt.h>
#include <sys/reboot.h>
#include "busybox.h"
-#include "init_shared.h"
+#include <unistd.h>
-extern int halt_main(int argc, char **argv)
+int halt_main(int argc, char *argv[])
{
- char *delay; /* delay in seconds before rebooting */
+ char *delay = "hpr";
+ int which, flags, magic[] = {RB_HALT_SYSTEM, RB_POWER_OFF, RB_AUTOBOOT},
+ signals[] = {SIGUSR1, SIGUSR2, SIGTERM}, rc = 1;
+
+ /* Figure out which applet we're running */
+ for(which=0;delay[which]!=*bb_applet_name;which++);
- if(bb_getopt_ulflags(argc, argv, "d:", &delay)) {
- sleep(atoi(delay));
- }
+ /* Parse and handle arguments */
+ flags = bb_getopt_ulflags(argc, argv, "d:nf", &delay);
+ if (flags&1) sleep(atoi(delay));
+ if (!(flags&2)) sync();
+
+ /* Perform action. */
+ if (ENABLE_INIT && !(flags & 4)) {
+ if (ENABLE_FEATURE_INITRD) {
+ long *pidlist=find_pid_by_name("linuxrc");
+ if (*pidlist>0) rc = kill(*pidlist,signals[which]);
+ if (ENABLE_FEATURE_CLEAN_UP) free(pidlist);
+ }
+ if (rc) rc = kill(1,signals[which]);
+ } else rc = reboot(magic[which]);
- return ENABLE_INIT ? kill(1,SIGUSR1) : bb_shutdown_system(RB_HALT_SYSTEM);
+ if (rc) bb_error_msg("No.");
+ return rc;
}
diff --git a/init/init.c b/init/init.c
index 337d31c2d..0db355413 100644
--- a/init/init.c
+++ b/init/init.c
@@ -751,14 +751,7 @@ static void exec_signal(int sig)
static void halt_signal(int sig)
{
shutdown_system();
- message(CONSOLE | LOG,
-#if #cpu(s390)
- /* Seems the s390 console is Wierd(tm). */
- "The system is halted. You may reboot now."
-#else
- "The system is halted. Press Reset or turn off power"
-#endif
- );
+ message(CONSOLE | LOG, "The system is halted.");
sync();
/* allow time for last message to reach serial console */
@@ -1024,11 +1017,9 @@ extern int init_main(int argc, char **argv)
}
#ifndef DEBUG_INIT
/* Expect to be invoked as init with PID=1 or be invoked as linuxrc */
- if (getpid() != 1
-#ifdef CONFIG_FEATURE_INITRD
- && strstr(bb_applet_name, "linuxrc") == NULL
-#endif
- ) {
+ if (getpid() != 1 &&
+ (!ENABLE_FEATURE_INITRD || !strstr(bb_applet_name, "linuxrc")))
+ {
bb_show_usage();
}
/* Set up sig handlers -- be sure to
diff --git a/init/poweroff.c b/init/poweroff.c
deleted file mode 100644
index b79bcd036..000000000
--- a/init/poweroff.c
+++ /dev/null
@@ -1,28 +0,0 @@
-/* vi: set sw=4 ts=4: */
-/*
- * Mini poweroff implementation for busybox
- *
- * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
- *
- * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
- */
-
-#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));
- }
-
- return ENABLE_INIT ? kill(1,SIGUSR2) : bb_shutdown_system(RB_POWER_OFF);
-}
diff --git a/init/reboot.c b/init/reboot.c
deleted file mode 100644
index 5508f0be9..000000000
--- a/init/reboot.c
+++ /dev/null
@@ -1,28 +0,0 @@
-/* vi: set sw=4 ts=4: */
-/*
- * Mini reboot implementation for busybox
- *
- * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
- *
- * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
- */
-
-#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 reboot_main(int argc, char **argv)
-{
- char *delay; /* delay in seconds before rebooting */
-
- if(bb_getopt_ulflags(argc, argv, "d:", &delay)) {
- sleep(atoi(delay));
- }
-
- return ENABLE_INIT ? kill(1,SIGTERM) : bb_shutdown_system(RB_AUTOBOOT);
-}