aboutsummaryrefslogtreecommitdiff
path: root/init
diff options
context:
space:
mode:
authorJeremie Koenig <jk@jk.fr.eu.org>2010-05-27 15:38:44 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2010-07-19 00:45:51 +0200
commit714674e4da3d92c5dd14e00ab30794a895b91eb4 (patch)
tree0d27bc73f1f2fe0175c5fc948451b86c52f9bb90 /init
parentf812eace1863feeac64dc8af27f4ab0f98119618 (diff)
downloadbusybox-w32-714674e4da3d92c5dd14e00ab30794a895b91eb4.tar.gz
busybox-w32-714674e4da3d92c5dd14e00ab30794a895b91eb4.tar.bz2
busybox-w32-714674e4da3d92c5dd14e00ab30794a895b91eb4.zip
init,halt: portability improvements
* make init and halt use the same RB_* constants for reboot() * conditionalize the Linux-specific code Inspired by init.init.diff from the Debian kFreeBSD patches at: http://svn.debian.org/viewsvn/d-i/people/slackydeb/kfreebsd/busybox/1.14/debian Signed-off-by: Jeremie Koenig <jk@jk.fr.eu.org> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'init')
-rw-r--r--init/Config.src2
-rw-r--r--init/halt.c14
-rw-r--r--init/init.c16
-rw-r--r--init/reboot.h31
4 files changed, 40 insertions, 23 deletions
diff --git a/init/Config.src b/init/Config.src
index a5e76be6a..590e29890 100644
--- a/init/Config.src
+++ b/init/Config.src
@@ -10,7 +10,6 @@ INSERT
10config INIT 10config INIT
11 bool "init" 11 bool "init"
12 default y 12 default y
13 depends on PLATFORM_LINUX
14 select FEATURE_SYSLOG 13 select FEATURE_SYSLOG
15 help 14 help
16 init is the first program run when the system boots. 15 init is the first program run when the system boots.
@@ -93,7 +92,6 @@ config FEATURE_INITRD
93config HALT 92config HALT
94 bool "poweroff, halt, and reboot" 93 bool "poweroff, halt, and reboot"
95 default y 94 default y
96 depends on PLATFORM_LINUX
97 help 95 help
98 Stop all processes and either halt, reboot, or power off the system. 96 Stop all processes and either halt, reboot, or power off the system.
99 97
diff --git a/init/halt.c b/init/halt.c
index f1bb2c4a8..abd801fda 100644
--- a/init/halt.c
+++ b/init/halt.c
@@ -8,7 +8,7 @@
8 */ 8 */
9 9
10#include "libbb.h" 10#include "libbb.h"
11#include <sys/reboot.h> 11#include "reboot.h"
12 12
13#if ENABLE_FEATURE_WTMP 13#if ENABLE_FEATURE_WTMP
14#include <sys/utsname.h> 14#include <sys/utsname.h>
@@ -36,18 +36,6 @@ static void write_wtmp(void)
36#define write_wtmp() ((void)0) 36#define write_wtmp() ((void)0)
37#endif 37#endif
38 38
39#ifndef RB_HALT_SYSTEM
40#define RB_HALT_SYSTEM RB_HALT
41#endif
42
43#ifndef RB_POWERDOWN
44/* Stop system and switch power off if possible. */
45# define RB_POWERDOWN 0x4321fedc
46#endif
47#ifndef RB_POWER_OFF
48# define RB_POWER_OFF RB_POWERDOWN
49#endif
50
51 39
52int halt_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 40int halt_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
53int halt_main(int argc UNUSED_PARAM, char **argv) 41int halt_main(int argc UNUSED_PARAM, char **argv)
diff --git a/init/init.c b/init/init.c
index 1388c75cc..d8bf15894 100644
--- a/init/init.c
+++ b/init/init.c
@@ -12,7 +12,6 @@
12#include "libbb.h" 12#include "libbb.h"
13#include <syslog.h> 13#include <syslog.h>
14#include <paths.h> 14#include <paths.h>
15#include <sys/reboot.h>
16#include <sys/resource.h> 15#include <sys/resource.h>
17#ifdef __linux__ 16#ifdef __linux__
18#include <linux/vt.h> 17#include <linux/vt.h>
@@ -20,6 +19,7 @@
20#if ENABLE_FEATURE_UTMP 19#if ENABLE_FEATURE_UTMP
21# include <utmp.h> /* DEAD_PROCESS */ 20# include <utmp.h> /* DEAD_PROCESS */
22#endif 21#endif
22#include "reboot.h" /* reboot() constants */
23 23
24/* Used only for sanitizing purposes in set_sane_term() below. On systems where 24/* Used only for sanitizing purposes in set_sane_term() below. On systems where
25 * the baud rate is stored in a separate field, we can safely disable them. */ 25 * the baud rate is stored in a separate field, we can safely disable them. */
@@ -97,13 +97,6 @@ static const char *log_console = VC_5;
97enum { 97enum {
98 L_LOG = 0x1, 98 L_LOG = 0x1,
99 L_CONSOLE = 0x2, 99 L_CONSOLE = 0x2,
100#ifndef RB_HALT_SYSTEM
101 RB_HALT_SYSTEM = 0xcdef0123, /* FIXME: this overflows enum */
102 RB_ENABLE_CAD = 0x89abcdef,
103 RB_DISABLE_CAD = 0,
104 RB_POWER_OFF = 0x4321fedc,
105 RB_AUTOBOOT = 0x01234567,
106#endif
107}; 100};
108 101
109/* Print a message to the specified device. 102/* Print a message to the specified device.
@@ -724,10 +717,12 @@ static void restart_handler(int sig UNUSED_PARAM)
724 717
725 run_shutdown_and_kill_processes(); 718 run_shutdown_and_kill_processes();
726 719
720#ifdef RB_ENABLE_CAD
727 /* Allow Ctrl-Alt-Del to reboot the system. 721 /* Allow Ctrl-Alt-Del to reboot the system.
728 * This is how kernel sets it up for init, we follow suit. 722 * This is how kernel sets it up for init, we follow suit.
729 */ 723 */
730 reboot(RB_ENABLE_CAD); /* misnomer */ 724 reboot(RB_ENABLE_CAD); /* misnomer */
725#endif
731 726
732 if (open_stdio_to_tty(a->terminal)) { 727 if (open_stdio_to_tty(a->terminal)) {
733 dbg_message(L_CONSOLE, "Trying to re-exec %s", a->command); 728 dbg_message(L_CONSOLE, "Trying to re-exec %s", a->command);
@@ -870,9 +865,11 @@ int init_main(int argc UNUSED_PARAM, char **argv)
870 ) { 865 ) {
871 bb_show_usage(); 866 bb_show_usage();
872 } 867 }
868#ifdef RB_DISABLE_CAD
873 /* Turn off rebooting via CTL-ALT-DEL - we get a 869 /* Turn off rebooting via CTL-ALT-DEL - we get a
874 * SIGINT on CAD so we can shut things down gracefully... */ 870 * SIGINT on CAD so we can shut things down gracefully... */
875 reboot(RB_DISABLE_CAD); /* misnomer */ 871 reboot(RB_DISABLE_CAD); /* misnomer */
872#endif
876 } 873 }
877 874
878 /* Figure out where the default console should be */ 875 /* Figure out where the default console should be */
@@ -895,6 +892,8 @@ int init_main(int argc UNUSED_PARAM, char **argv)
895 message(L_CONSOLE | L_LOG, "init started: %s", bb_banner); 892 message(L_CONSOLE | L_LOG, "init started: %s", bb_banner);
896#endif 893#endif
897 894
895/* struct sysinfo is linux-specific */
896#ifdef __linux__
898 /* Make sure there is enough memory to do something useful. */ 897 /* Make sure there is enough memory to do something useful. */
899 if (ENABLE_SWAPONOFF) { 898 if (ENABLE_SWAPONOFF) {
900 struct sysinfo info; 899 struct sysinfo info;
@@ -910,6 +909,7 @@ int init_main(int argc UNUSED_PARAM, char **argv)
910 run_actions(SYSINIT); /* wait and removing */ 909 run_actions(SYSINIT); /* wait and removing */
911 } 910 }
912 } 911 }
912#endif
913 913
914 /* Check if we are supposed to be in single user mode */ 914 /* Check if we are supposed to be in single user mode */
915 if (argv[1] 915 if (argv[1]
diff --git a/init/reboot.h b/init/reboot.h
new file mode 100644
index 000000000..ff045fdd1
--- /dev/null
+++ b/init/reboot.h
@@ -0,0 +1,31 @@
1/*
2 * Definitions related to the reboot() system call,
3 * shared between init.c and halt.c.
4 */
5
6#include <sys/reboot.h>
7
8#ifndef RB_HALT_SYSTEM
9# if defined(__linux__)
10# define RB_HALT_SYSTEM 0xcdef0123
11# define RB_ENABLE_CAD 0x89abcdef
12# define RB_DISABLE_CAD 0
13# define RB_POWER_OFF 0x4321fedc
14# define RB_AUTOBOOT 0x01234567
15# elif defined(RB_HALT)
16# define RB_HALT_SYSTEM RB_HALT
17# endif
18#endif
19
20/* Stop system and switch power off if possible. */
21#ifndef RB_POWER_OFF
22# if defined(RB_POWERDOWN)
23# define RB_POWER_OFF RB_POWERDOWN
24# elif defined(__linux__)
25# define RB_POWER_OFF 0x4321fedc
26# else
27# warning "poweroff unsupported, using halt as fallback"
28# define RB_POWER_OFF RB_HALT_SYSTEM
29# endif
30#endif
31