aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2006-01-30 08:31:37 +0000
committerRob Landley <rob@landley.net>2006-01-30 08:31:37 +0000
commit646129163a26171d48a335f7e22828848cf28cc5 (patch)
tree1e57cdfe9be4ec15c27276389a760f3ad6b5ab34
parent49576c0018358beda0e79e0ebb247b90e347e6e0 (diff)
downloadbusybox-w32-646129163a26171d48a335f7e22828848cf28cc5.tar.gz
busybox-w32-646129163a26171d48a335f7e22828848cf28cc5.tar.bz2
busybox-w32-646129163a26171d48a335f7e22828848cf28cc5.zip
Re-add initrd support, unify halt/reboot/poweroff, add -n and -f options.
-rw-r--r--include/applets.h8
-rw-r--r--include/usage.h20
-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
7 files changed, 73 insertions, 121 deletions
diff --git a/include/applets.h b/include/applets.h
index 1fb279ffa..6eb5cfd5f 100644
--- a/include/applets.h
+++ b/include/applets.h
@@ -517,8 +517,8 @@
517#ifdef CONFIG_PIVOT_ROOT 517#ifdef CONFIG_PIVOT_ROOT
518 APPLET(pivot_root, pivot_root_main, _BB_DIR_SBIN, _BB_SUID_NEVER) 518 APPLET(pivot_root, pivot_root_main, _BB_DIR_SBIN, _BB_SUID_NEVER)
519#endif 519#endif
520#ifdef CONFIG_POWEROFF 520#ifdef CONFIG_HALT
521 APPLET(poweroff, poweroff_main, _BB_DIR_SBIN, _BB_SUID_NEVER) 521 APPLET(poweroff, halt_main, _BB_DIR_SBIN, _BB_SUID_NEVER)
522#endif 522#endif
523#ifdef CONFIG_PRINTENV 523#ifdef CONFIG_PRINTENV
524 APPLET(printenv, printenv_main, _BB_DIR_BIN, _BB_SUID_NEVER) 524 APPLET(printenv, printenv_main, _BB_DIR_BIN, _BB_SUID_NEVER)
@@ -544,8 +544,8 @@
544#ifdef CONFIG_REALPATH 544#ifdef CONFIG_REALPATH
545 APPLET(realpath, realpath_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) 545 APPLET(realpath, realpath_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
546#endif 546#endif
547#ifdef CONFIG_REBOOT 547#ifdef CONFIG_HALT
548 APPLET(reboot, reboot_main, _BB_DIR_SBIN, _BB_SUID_NEVER) 548 APPLET(reboot, halt_main, _BB_DIR_SBIN, _BB_SUID_NEVER)
549#endif 549#endif
550#ifdef CONFIG_RENICE 550#ifdef CONFIG_RENICE
551 APPLET(renice, renice_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) 551 APPLET(renice, renice_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
diff --git a/include/usage.h b/include/usage.h
index 61fc3af3c..71752c7d5 100644
--- a/include/usage.h
+++ b/include/usage.h
@@ -1010,11 +1010,13 @@
1010 "-rw-rw-r-- 1 andersen andersen 554058 Apr 14 17:49 /tmp/busybox.tar.gz\n" 1010 "-rw-rw-r-- 1 andersen andersen 554058 Apr 14 17:49 /tmp/busybox.tar.gz\n"
1011 1011
1012#define halt_trivial_usage \ 1012#define halt_trivial_usage \
1013 "[-d<delay>]" 1013 "[-d<delay>] [-n<nosync>] [-f<force>]"
1014#define halt_full_usage \ 1014#define halt_full_usage \
1015 "Halt the system.\n" \ 1015 "Halt the system.\n" \
1016 "Options:\n" \ 1016 "Options:\n" \
1017 "\t-d\t\tdelay interval for halting" 1017 "\t-d\t\tdelay interval for halting\n" \
1018 "\t-n\t\tno call to sync()\n" \
1019 "\t-f\t\tforce halt (don't go through init)\n"
1018 1020
1019#ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY 1021#ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY
1020#define USAGE_HDPARM_IDENT(a) a 1022#define USAGE_HDPARM_IDENT(a) a
@@ -2372,11 +2374,13 @@
2372 "the new root file system." 2374 "the new root file system."
2373 2375
2374#define poweroff_trivial_usage \ 2376#define poweroff_trivial_usage \
2375 "[-d<delay>]" 2377 "[-d<delay>] [-n<nosync>] [-f<force>]"
2376#define poweroff_full_usage \ 2378#define poweroff_full_usage \
2377 "Halt the system and request that the kernel shut off the power.\n" \ 2379 "Halt and shut off power.\n" \
2378 "Options:\n" \ 2380 "Options:\n" \
2379 "\t-d\t\tdelay interval for shutting off" 2381 "\t-d\t\tdelay interval for halting\n" \
2382 "\t-n\t\tno call to sync()\n" \
2383 "\t-f\t\tforce power off (don't go through init)\n"
2380 2384
2381#define printenv_trivial_usage \ 2385#define printenv_trivial_usage \
2382 "[VARIABLES...]" 2386 "[VARIABLES...]"
@@ -2475,11 +2479,13 @@
2475 "Returns the absolute pathnames of given argument." 2479 "Returns the absolute pathnames of given argument."
2476 2480
2477#define reboot_trivial_usage \ 2481#define reboot_trivial_usage \
2478 "[-d<delay>]" 2482 "[-d<delay>] [-n<nosync>] [-f<force>]"
2479#define reboot_full_usage \ 2483#define reboot_full_usage \
2480 "Reboot the system.\n" \ 2484 "Reboot the system.\n" \
2481 "Options:\n" \ 2485 "Options:\n" \
2482 "\t-d\t\tdelay interval for rebooting" 2486 "\t-d\t\tdelay interval for rebooting\n" \
2487 "\t-n\t\tno call to sync()\n" \
2488 "\t-f\t\tforce reboot (don't go through init)\n"
2483 2489
2484#define renice_trivial_usage \ 2490#define renice_trivial_usage \
2485 "{{-n INCREMENT} | PRIORITY} [[ -p | -g | -u ] ID ...]" 2491 "{{-n INCREMENT} | PRIORITY} [[ -p | -g | -u ] ID ...]"
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
12 init is the first program run when the system boots. 12 init is the first program run when the system boots.
13 13
14config CONFIG_FEATURE_USE_INITTAB 14config CONFIG_FEATURE_USE_INITTAB
15 bool " Support reading an inittab file?" 15 bool " Support reading an inittab file"
16 default y 16 default y
17 depends on CONFIG_INIT 17 depends on CONFIG_INIT
18 help 18 help
19 Allow init to read an inittab file when the system boot. 19 Allow init to read an inittab file when the system boot.
20 20
21config CONFIG_FEATURE_INITRD 21config CONFIG_FEATURE_INIT_SCTTY
22 bool " Support running init from within an initrd?" 22 bool " Support running commands with a controlling-tty"
23 default n
24 depends on CONFIG_INIT
25 help
26 If this option is enabled a command starting with hyphen (-)
27 is run in its own session (setsid(2)) and possibly with a
28 controlling tty (TIOCSCTTY). This is not the traditional init
29 behavour, but is often what you want in an embedded system where
30 the console is only accessed during development or for maintenance.
31
32config CONFIG_FEATURE_EXTRA_QUIET
33 bool " Be _extra_ quiet on boot"
23 default y 34 default y
24 depends on CONFIG_INIT 35 depends on CONFIG_INIT
25 help 36 help
26 Allow init to be called from an initrd as linuxrc. 37 Prevent init from logging some messages to the console during boot.
27 38
28config CONFIG_FEATURE_INIT_COREDUMPS 39config CONFIG_FEATURE_INIT_COREDUMPS
29 bool " Support dumping core for child processes (debugging only)?" 40 bool " Support dumping core for child processes (debugging only)"
30 default n 41 default n
31 depends on CONFIG_INIT 42 depends on CONFIG_INIT
32 help 43 help
@@ -35,30 +46,24 @@ config CONFIG_FEATURE_INIT_COREDUMPS
35 core file sizes. If this option is disabled, processes 46 core file sizes. If this option is disabled, processes
36 will not generate any core files. 47 will not generate any core files.
37 48
38config CONFIG_FEATURE_INIT_SCTTY
39 bool " Support running commands with a controlling-tty?"
40 default n
41 depends on CONFIG_INIT
42 help
43 If this option is enabled a command starting with hyphen (-)
44 is run in its own session (setsid(2)) and possibly with a
45 controlling tty (TIOCSCTTY). This is not the traditional init
46 behavour, but is often what you want in an embedded system where
47 the console is only accessed during development or for maintenance.
48 49
49config CONFIG_FEATURE_EXTRA_QUIET 50
50 bool " Should init be _extra_ quiet on boot?" 51config CONFIG_FEATURE_INITRD
52 bool " Support running init from within an initrd (not initramfs)"
51 default y 53 default y
52 depends on CONFIG_INIT 54 depends on CONFIG_INIT
53 help 55 help
54 Prevent init from logging some messages to the console 56 Legacy support for running init under the old-style initrd. Allows
55 during boot. 57 the name linuxrc to act as init, and it doesn't assume init is PID 1.
58
59 This does not apply to initramfs, which runs /init as PID 1 and
60 requires no special support.
56 61
57config CONFIG_HALT 62config CONFIG_HALT
58 bool "halt" 63 bool "poweroff, halt, and reboot"
59 default y 64 default y
60 help 65 help
61 Stop all processes and halt the system. 66 Stop all processes and either halt, reboot, or power off the system.
62 67
63config CONFIG_MESG 68config CONFIG_MESG
64 bool "mesg" 69 bool "mesg"
@@ -67,17 +72,9 @@ config CONFIG_MESG
67 Mesg controls access to your terminal by others. It is typically 72 Mesg controls access to your terminal by others. It is typically
68 used to allow or disallow other users to write to your terminal 73 used to allow or disallow other users to write to your terminal
69 74
70config CONFIG_POWEROFF
71 bool "poweroff"
72 default y 75 default y
73 help 76 help
74 Stop all processes and (try to) power off the system. 77 Stop all processes and (try to) power off the system.
75 78
76config CONFIG_REBOOT
77 bool "reboot"
78 default y
79 help
80 Stop all processes and reboot the system.
81
82endmenu 79endmenu
83 80
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 @@
1/* vi: set sw=4 ts=4: */ 1/* vi: set sw=4 ts=4: */
2/* 2/*
3 * Mini halt implementation for busybox 3 * Poweroff reboot and halt, oh my.
4 * 4 *
5 * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org> 5 * Copyright 2006 by Rob Landley <rob@landley.net>
6 * 6 *
7 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. 7 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
8 */ 8 */
9 9
10#include <signal.h> 10#include <signal.h>
11#include <stdlib.h>
12#include <unistd.h>
13#include <getopt.h>
14#include <sys/reboot.h> 11#include <sys/reboot.h>
15#include "busybox.h" 12#include "busybox.h"
16#include "init_shared.h"
17 13
14#include <unistd.h>
18 15
19extern int halt_main(int argc, char **argv) 16int halt_main(int argc, char *argv[])
20{ 17{
21 char *delay; /* delay in seconds before rebooting */ 18 char *delay = "hpr";
19 int which, flags, magic[] = {RB_HALT_SYSTEM, RB_POWER_OFF, RB_AUTOBOOT},
20 signals[] = {SIGUSR1, SIGUSR2, SIGTERM}, rc = 1;
21
22 /* Figure out which applet we're running */
23 for(which=0;delay[which]!=*bb_applet_name;which++);
22 24
23 if(bb_getopt_ulflags(argc, argv, "d:", &delay)) { 25 /* Parse and handle arguments */
24 sleep(atoi(delay)); 26 flags = bb_getopt_ulflags(argc, argv, "d:nf", &delay);
25 } 27 if (flags&1) sleep(atoi(delay));
28 if (!(flags&2)) sync();
29
30 /* Perform action. */
31 if (ENABLE_INIT && !(flags & 4)) {
32 if (ENABLE_FEATURE_INITRD) {
33 long *pidlist=find_pid_by_name("linuxrc");
34 if (*pidlist>0) rc = kill(*pidlist,signals[which]);
35 if (ENABLE_FEATURE_CLEAN_UP) free(pidlist);
36 }
37 if (rc) rc = kill(1,signals[which]);
38 } else rc = reboot(magic[which]);
26 39
27 return ENABLE_INIT ? kill(1,SIGUSR1) : bb_shutdown_system(RB_HALT_SYSTEM); 40 if (rc) bb_error_msg("No.");
41 return rc;
28} 42}
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)
751static void halt_signal(int sig) 751static void halt_signal(int sig)
752{ 752{
753 shutdown_system(); 753 shutdown_system();
754 message(CONSOLE | LOG, 754 message(CONSOLE | LOG, "The system is halted.");
755#if #cpu(s390)
756 /* Seems the s390 console is Wierd(tm). */
757 "The system is halted. You may reboot now."
758#else
759 "The system is halted. Press Reset or turn off power"
760#endif
761 );
762 sync(); 755 sync();
763 756
764 /* allow time for last message to reach serial console */ 757 /* allow time for last message to reach serial console */
@@ -1024,11 +1017,9 @@ extern int init_main(int argc, char **argv)
1024 } 1017 }
1025#ifndef DEBUG_INIT 1018#ifndef DEBUG_INIT
1026 /* Expect to be invoked as init with PID=1 or be invoked as linuxrc */ 1019 /* Expect to be invoked as init with PID=1 or be invoked as linuxrc */
1027 if (getpid() != 1 1020 if (getpid() != 1 &&
1028#ifdef CONFIG_FEATURE_INITRD 1021 (!ENABLE_FEATURE_INITRD || !strstr(bb_applet_name, "linuxrc")))
1029 && strstr(bb_applet_name, "linuxrc") == NULL 1022 {
1030#endif
1031 ) {
1032 bb_show_usage(); 1023 bb_show_usage();
1033 } 1024 }
1034 /* Set up sig handlers -- be sure to 1025 /* 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 @@
1/* vi: set sw=4 ts=4: */
2/*
3 * Mini poweroff implementation for busybox
4 *
5 * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
6 *
7 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
8 */
9
10#include <signal.h>
11#include <stdlib.h>
12#include <unistd.h>
13#include <getopt.h>
14#include <sys/reboot.h>
15#include "busybox.h"
16#include "init_shared.h"
17
18
19extern int poweroff_main(int argc, char **argv)
20{
21 char *delay; /* delay in seconds before rebooting */
22
23 if(bb_getopt_ulflags(argc, argv, "d:", &delay)) {
24 sleep(atoi(delay));
25 }
26
27 return ENABLE_INIT ? kill(1,SIGUSR2) : bb_shutdown_system(RB_POWER_OFF);
28}
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 @@
1/* vi: set sw=4 ts=4: */
2/*
3 * Mini reboot implementation for busybox
4 *
5 * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
6 *
7 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
8 */
9
10#include <signal.h>
11#include <stdlib.h>
12#include <unistd.h>
13#include <getopt.h>
14#include <sys/reboot.h>
15#include "busybox.h"
16#include "init_shared.h"
17
18
19extern int reboot_main(int argc, char **argv)
20{
21 char *delay; /* delay in seconds before rebooting */
22
23 if(bb_getopt_ulflags(argc, argv, "d:", &delay)) {
24 sleep(atoi(delay));
25 }
26
27 return ENABLE_INIT ? kill(1,SIGTERM) : bb_shutdown_system(RB_AUTOBOOT);
28}