1 From 714674e4da3d92c5dd14e00ab30794a895b91eb4 Mon Sep 17 00:00:00 2001
2 From: Jeremie Koenig <jk@jk.fr.eu.org>
3 Date: Thu, 27 May 2010 15:38:44 +0200
4 Subject: [PATCH 4/9] init,halt: portability improvements
6 * make init and halt use the same RB_* constants for reboot()
7 * conditionalize the Linux-specific code
9 Inspired by init.init.diff from the Debian kFreeBSD patches at:
10 http://svn.debian.org/viewsvn/d-i/people/slackydeb/kfreebsd/busybox/1.14/debian
12 Signed-off-by: Jeremie Koenig <jk@jk.fr.eu.org>
13 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
15 init/Config.src | 2 --
16 init/halt.c | 14 +-------------
17 init/init.c | 16 ++++++++--------
18 init/reboot.h | 31 +++++++++++++++++++++++++++++++
19 4 files changed, 40 insertions(+), 23 deletions(-)
20 create mode 100644 init/reboot.h
22 Index: busybox-1.17.1/init/Config.src
23 ===================================================================
24 --- busybox-1.17.1.orig/init/Config.src 2010-08-01 05:32:43.000000000 +0200
25 +++ busybox-1.17.1/init/Config.src 2010-08-01 05:36:47.000000000 +0200
30 - depends on PLATFORM_LINUX
33 init is the first program run when the system boots.
36 bool "poweroff, halt, and reboot"
38 - depends on PLATFORM_LINUX
40 Stop all processes and either halt, reboot, or power off the system.
42 Index: busybox-1.17.1/init/halt.c
43 ===================================================================
44 --- busybox-1.17.1.orig/init/halt.c 2010-07-25 00:12:43.000000000 +0200
45 +++ busybox-1.17.1/init/halt.c 2010-08-01 05:36:47.000000000 +0200
50 -#include <sys/reboot.h>
53 #if ENABLE_FEATURE_WTMP
54 #include <sys/utsname.h>
56 #define write_wtmp() ((void)0)
59 -#ifndef RB_HALT_SYSTEM
60 -#define RB_HALT_SYSTEM RB_HALT
64 -/* Stop system and switch power off if possible. */
65 -# define RB_POWERDOWN 0x4321fedc
68 -# define RB_POWER_OFF RB_POWERDOWN
72 int halt_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
73 int halt_main(int argc UNUSED_PARAM, char **argv)
74 Index: busybox-1.17.1/init/init.c
75 ===================================================================
76 --- busybox-1.17.1.orig/init/init.c 2010-08-01 05:36:45.000000000 +0200
77 +++ busybox-1.17.1/init/init.c 2010-08-01 05:36:47.000000000 +0200
82 -#include <sys/reboot.h>
83 #include <sys/resource.h>
87 #if ENABLE_FEATURE_UTMP
88 # include <utmp.h> /* DEAD_PROCESS */
90 +#include "reboot.h" /* reboot() constants */
92 /* Used only for sanitizing purposes in set_sane_term() below. On systems where
93 * the baud rate is stored in a separate field, we can safely disable them. */
98 -#ifndef RB_HALT_SYSTEM
99 - RB_HALT_SYSTEM = 0xcdef0123, /* FIXME: this overflows enum */
100 - RB_ENABLE_CAD = 0x89abcdef,
101 - RB_DISABLE_CAD = 0,
102 - RB_POWER_OFF = 0x4321fedc,
103 - RB_AUTOBOOT = 0x01234567,
107 /* Print a message to the specified device.
108 @@ -726,10 +719,12 @@
110 run_shutdown_and_kill_processes();
112 +#ifdef RB_ENABLE_CAD
113 /* Allow Ctrl-Alt-Del to reboot the system.
114 * This is how kernel sets it up for init, we follow suit.
116 reboot(RB_ENABLE_CAD); /* misnomer */
119 if (open_stdio_to_tty(a->terminal)) {
120 dbg_message(L_CONSOLE, "Trying to re-exec %s", a->command);
125 +#ifdef RB_DISABLE_CAD
126 /* Turn off rebooting via CTL-ALT-DEL - we get a
127 * SIGINT on CAD so we can shut things down gracefully... */
128 reboot(RB_DISABLE_CAD); /* misnomer */
132 /* Figure out where the default console should be */
134 message(L_CONSOLE | L_LOG, "init started: %s", bb_banner);
137 +/* struct sysinfo is linux-specific */
139 /* Make sure there is enough memory to do something useful. */
140 if (ENABLE_SWAPONOFF) {
143 run_actions(SYSINIT); /* wait and removing */
148 /* Check if we are supposed to be in single user mode */
150 Index: busybox-1.17.1/init/reboot.h
151 ===================================================================
152 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
153 +++ busybox-1.17.1/init/reboot.h 2010-08-01 05:36:47.000000000 +0200
156 + * Definitions related to the reboot() system call,
157 + * shared between init.c and halt.c.
160 +#include <sys/reboot.h>
162 +#ifndef RB_HALT_SYSTEM
163 +# if defined(__linux__)
164 +# define RB_HALT_SYSTEM 0xcdef0123
165 +# define RB_ENABLE_CAD 0x89abcdef
166 +# define RB_DISABLE_CAD 0
167 +# define RB_POWER_OFF 0x4321fedc
168 +# define RB_AUTOBOOT 0x01234567
169 +# elif defined(RB_HALT)
170 +# define RB_HALT_SYSTEM RB_HALT
174 +/* Stop system and switch power off if possible. */
175 +#ifndef RB_POWER_OFF
176 +# if defined(RB_POWERDOWN)
177 +# define RB_POWER_OFF RB_POWERDOWN
178 +# elif defined(__linux__)
179 +# define RB_POWER_OFF 0x4321fedc
181 +# warning "poweroff unsupported, using halt as fallback"
182 +# define RB_POWER_OFF RB_HALT_SYSTEM