Re-add initrd support, unify halt/reboot/poweroff, add -n and -f options.

This commit is contained in:
Rob Landley 2006-01-30 08:31:37 +00:00
parent 49576c0018
commit 646129163a
7 changed files with 76 additions and 124 deletions

View File

@ -517,8 +517,8 @@
#ifdef CONFIG_PIVOT_ROOT #ifdef CONFIG_PIVOT_ROOT
APPLET(pivot_root, pivot_root_main, _BB_DIR_SBIN, _BB_SUID_NEVER) APPLET(pivot_root, pivot_root_main, _BB_DIR_SBIN, _BB_SUID_NEVER)
#endif #endif
#ifdef CONFIG_POWEROFF #ifdef CONFIG_HALT
APPLET(poweroff, poweroff_main, _BB_DIR_SBIN, _BB_SUID_NEVER) APPLET(poweroff, halt_main, _BB_DIR_SBIN, _BB_SUID_NEVER)
#endif #endif
#ifdef CONFIG_PRINTENV #ifdef CONFIG_PRINTENV
APPLET(printenv, printenv_main, _BB_DIR_BIN, _BB_SUID_NEVER) APPLET(printenv, printenv_main, _BB_DIR_BIN, _BB_SUID_NEVER)
@ -544,8 +544,8 @@
#ifdef CONFIG_REALPATH #ifdef CONFIG_REALPATH
APPLET(realpath, realpath_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) APPLET(realpath, realpath_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
#endif #endif
#ifdef CONFIG_REBOOT #ifdef CONFIG_HALT
APPLET(reboot, reboot_main, _BB_DIR_SBIN, _BB_SUID_NEVER) APPLET(reboot, halt_main, _BB_DIR_SBIN, _BB_SUID_NEVER)
#endif #endif
#ifdef CONFIG_RENICE #ifdef CONFIG_RENICE
APPLET(renice, renice_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) APPLET(renice, renice_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)

View File

@ -1010,11 +1010,13 @@
"-rw-rw-r-- 1 andersen andersen 554058 Apr 14 17:49 /tmp/busybox.tar.gz\n" "-rw-rw-r-- 1 andersen andersen 554058 Apr 14 17:49 /tmp/busybox.tar.gz\n"
#define halt_trivial_usage \ #define halt_trivial_usage \
"[-d<delay>]" "[-d<delay>] [-n<nosync>] [-f<force>]"
#define halt_full_usage \ #define halt_full_usage \
"Halt the system.\n" \ "Halt the system.\n" \
"Options:\n" \ "Options:\n" \
"\t-d\t\tdelay interval for halting" "\t-d\t\tdelay interval for halting\n" \
"\t-n\t\tno call to sync()\n" \
"\t-f\t\tforce halt (don't go through init)\n"
#ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY #ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY
#define USAGE_HDPARM_IDENT(a) a #define USAGE_HDPARM_IDENT(a) a
@ -2372,11 +2374,13 @@
"the new root file system." "the new root file system."
#define poweroff_trivial_usage \ #define poweroff_trivial_usage \
"[-d<delay>]" "[-d<delay>] [-n<nosync>] [-f<force>]"
#define poweroff_full_usage \ #define poweroff_full_usage \
"Halt the system and request that the kernel shut off the power.\n" \ "Halt and shut off power.\n" \
"Options:\n" \ "Options:\n" \
"\t-d\t\tdelay interval for shutting off" "\t-d\t\tdelay interval for halting\n" \
"\t-n\t\tno call to sync()\n" \
"\t-f\t\tforce power off (don't go through init)\n"
#define printenv_trivial_usage \ #define printenv_trivial_usage \
"[VARIABLES...]" "[VARIABLES...]"
@ -2475,11 +2479,13 @@
"Returns the absolute pathnames of given argument." "Returns the absolute pathnames of given argument."
#define reboot_trivial_usage \ #define reboot_trivial_usage \
"[-d<delay>]" "[-d<delay>] [-n<nosync>] [-f<force>]"
#define reboot_full_usage \ #define reboot_full_usage \
"Reboot the system.\n" \ "Reboot the system.\n" \
"Options:\n" \ "Options:\n" \
"\t-d\t\tdelay interval for rebooting" "\t-d\t\tdelay interval for rebooting\n" \
"\t-n\t\tno call to sync()\n" \
"\t-f\t\tforce reboot (don't go through init)\n"
#define renice_trivial_usage \ #define renice_trivial_usage \
"{{-n INCREMENT} | PRIORITY} [[ -p | -g | -u ] ID ...]" "{{-n INCREMENT} | PRIORITY} [[ -p | -g | -u ] ID ...]"

View File

@ -12,31 +12,14 @@ config CONFIG_INIT
init is the first program run when the system boots. init is the first program run when the system boots.
config CONFIG_FEATURE_USE_INITTAB config CONFIG_FEATURE_USE_INITTAB
bool " Support reading an inittab file?" bool " Support reading an inittab file"
default y default y
depends on CONFIG_INIT depends on CONFIG_INIT
help help
Allow init to read an inittab file when the system boot. Allow init to read an inittab file when the system boot.
config CONFIG_FEATURE_INITRD
bool " Support running init from within an initrd?"
default y
depends on CONFIG_INIT
help
Allow init to be called from an initrd as linuxrc.
config CONFIG_FEATURE_INIT_COREDUMPS
bool " Support dumping core for child processes (debugging only)?"
default n
depends on CONFIG_INIT
help
If this option is enabled and the file /.init_enable_core
exists, then init will call setrlimit() to allow unlimited
core file sizes. If this option is disabled, processes
will not generate any core files.
config CONFIG_FEATURE_INIT_SCTTY config CONFIG_FEATURE_INIT_SCTTY
bool " Support running commands with a controlling-tty?" bool " Support running commands with a controlling-tty"
default n default n
depends on CONFIG_INIT depends on CONFIG_INIT
help help
@ -47,18 +30,40 @@ config CONFIG_FEATURE_INIT_SCTTY
the console is only accessed during development or for maintenance. the console is only accessed during development or for maintenance.
config CONFIG_FEATURE_EXTRA_QUIET config CONFIG_FEATURE_EXTRA_QUIET
bool " Should init be _extra_ quiet on boot?" bool " Be _extra_ quiet on boot"
default y default y
depends on CONFIG_INIT depends on CONFIG_INIT
help help
Prevent init from logging some messages to the console Prevent init from logging some messages to the console during boot.
during boot.
config CONFIG_FEATURE_INIT_COREDUMPS
bool " Support dumping core for child processes (debugging only)"
default n
depends on CONFIG_INIT
help
If this option is enabled and the file /.init_enable_core
exists, then init will call setrlimit() to allow unlimited
core file sizes. If this option is disabled, processes
will not generate any core files.
config CONFIG_FEATURE_INITRD
bool " Support running init from within an initrd (not initramfs)"
default y
depends on CONFIG_INIT
help
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 config CONFIG_HALT
bool "halt" bool "poweroff, halt, and reboot"
default y default y
help help
Stop all processes and halt the system. Stop all processes and either halt, reboot, or power off the system.
config CONFIG_MESG config CONFIG_MESG
bool "mesg" bool "mesg"
@ -67,17 +72,9 @@ config CONFIG_MESG
Mesg controls access to your terminal by others. It is typically Mesg controls access to your terminal by others. It is typically
used to allow or disallow other users to write to your terminal used to allow or disallow other users to write to your terminal
config CONFIG_POWEROFF
bool "poweroff"
default y default y
help help
Stop all processes and (try to) power off the system. 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 endmenu

View File

@ -1,28 +1,42 @@
/* vi: set sw=4 ts=4: */ /* 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. * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/ */
#include <signal.h> #include <signal.h>
#include <stdlib.h>
#include <unistd.h>
#include <getopt.h>
#include <sys/reboot.h> #include <sys/reboot.h>
#include "busybox.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;
if(bb_getopt_ulflags(argc, argv, "d:", &delay)) { /* Figure out which applet we're running */
sleep(atoi(delay)); for(which=0;delay[which]!=*bb_applet_name;which++);
}
return ENABLE_INIT ? kill(1,SIGUSR1) : bb_shutdown_system(RB_HALT_SYSTEM); /* 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]);
if (rc) bb_error_msg("No.");
return rc;
} }

View File

@ -751,14 +751,7 @@ static void exec_signal(int sig)
static void halt_signal(int sig) static void halt_signal(int sig)
{ {
shutdown_system(); shutdown_system();
message(CONSOLE | LOG, message(CONSOLE | LOG, "The system is halted.");
#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
);
sync(); sync();
/* allow time for last message to reach serial console */ /* allow time for last message to reach serial console */
@ -1024,11 +1017,9 @@ extern int init_main(int argc, char **argv)
} }
#ifndef DEBUG_INIT #ifndef DEBUG_INIT
/* Expect to be invoked as init with PID=1 or be invoked as linuxrc */ /* Expect to be invoked as init with PID=1 or be invoked as linuxrc */
if (getpid() != 1 if (getpid() != 1 &&
#ifdef CONFIG_FEATURE_INITRD (!ENABLE_FEATURE_INITRD || !strstr(bb_applet_name, "linuxrc")))
&& strstr(bb_applet_name, "linuxrc") == NULL {
#endif
) {
bb_show_usage(); bb_show_usage();
} }
/* Set up sig handlers -- be sure to /* Set up sig handlers -- be sure to

View File

@ -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);
}

View File

@ -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);
}