94618c3d77e193601e16e2314c3df7b86fca32c5
[external/busybox.git] / util-linux / debian / patches / init-halt-portability-improvements.patch
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
5
6 * make init and halt use the same RB_* constants for reboot()
7 * conditionalize the Linux-specific code
8
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
11
12 Signed-off-by: Jeremie Koenig <jk@jk.fr.eu.org>
13 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
14 ---
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
21
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
26 @@ -10,7 +10,6 @@
27  config INIT
28         bool "init"
29         default y
30 -       depends on PLATFORM_LINUX
31         select FEATURE_SYSLOG
32         help
33           init is the first program run when the system boots.
34 @@ -93,7 +92,6 @@
35  config HALT
36         bool "poweroff, halt, and reboot"
37         default y
38 -       depends on PLATFORM_LINUX
39         help
40           Stop all processes and either halt, reboot, or power off the system.
41  
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
46 @@ -8,7 +8,7 @@
47   */
48  
49  #include "libbb.h"
50 -#include <sys/reboot.h>
51 +#include "reboot.h"
52  
53  #if ENABLE_FEATURE_WTMP
54  #include <sys/utsname.h>
55 @@ -36,18 +36,6 @@
56  #define write_wtmp() ((void)0)
57  #endif
58  
59 -#ifndef RB_HALT_SYSTEM
60 -#define RB_HALT_SYSTEM RB_HALT
61 -#endif
62 -
63 -#ifndef RB_POWERDOWN
64 -/* Stop system and switch power off if possible.  */
65 -# define RB_POWERDOWN   0x4321fedc
66 -#endif
67 -#ifndef RB_POWER_OFF
68 -# define RB_POWER_OFF RB_POWERDOWN
69 -#endif
70 -
71  
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
78 @@ -12,7 +12,6 @@
79  #include "libbb.h"
80  #include <syslog.h>
81  #include <paths.h>
82 -#include <sys/reboot.h>
83  #include <sys/resource.h>
84  #ifdef __linux__
85  #include <linux/vt.h>
86 @@ -20,6 +19,7 @@
87  #if ENABLE_FEATURE_UTMP
88  # include <utmp.h> /* DEAD_PROCESS */
89  #endif
90 +#include "reboot.h" /* reboot() constants */
91  
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. */
94 @@ -97,13 +97,6 @@
95  enum {
96         L_LOG = 0x1,
97         L_CONSOLE = 0x2,
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,
104 -#endif
105  };
106  
107  /* Print a message to the specified device.
108 @@ -726,10 +719,12 @@
109  
110                 run_shutdown_and_kill_processes();
111  
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.
115                  */
116                 reboot(RB_ENABLE_CAD); /* misnomer */
117 +#endif
118  
119                 if (open_stdio_to_tty(a->terminal)) {
120                         dbg_message(L_CONSOLE, "Trying to re-exec %s", a->command);
121 @@ -872,9 +867,11 @@
122                 ) {
123                         bb_show_usage();
124                 }
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 */
129 +#endif
130         }
131  
132         /* Figure out where the default console should be */
133 @@ -897,6 +894,8 @@
134         message(L_CONSOLE | L_LOG, "init started: %s", bb_banner);
135  #endif
136  
137 +/* struct sysinfo is linux-specific */
138 +#ifdef __linux__
139         /* Make sure there is enough memory to do something useful. */
140         if (ENABLE_SWAPONOFF) {
141                 struct sysinfo info;
142 @@ -912,6 +911,7 @@
143                         run_actions(SYSINIT);   /* wait and removing */
144                 }
145         }
146 +#endif
147  
148         /* Check if we are supposed to be in single user mode */
149         if (argv[1]
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
154 @@ -0,0 +1,31 @@
155 +/*
156 + * Definitions related to the reboot() system call,
157 + * shared between init.c and halt.c.
158 + */
159 +
160 +#include <sys/reboot.h>
161 +
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
171 +# endif
172 +#endif
173 +
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
180 +# else
181 +#  warning "poweroff unsupported, using halt as fallback"
182 +#  define RB_POWER_OFF  RB_HALT_SYSTEM
183 +# endif
184 +#endif
185 +