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>
This commit is contained in:
parent
f812eace18
commit
714674e4da
@ -10,7 +10,6 @@ INSERT
|
|||||||
config INIT
|
config INIT
|
||||||
bool "init"
|
bool "init"
|
||||||
default y
|
default y
|
||||||
depends on PLATFORM_LINUX
|
|
||||||
select FEATURE_SYSLOG
|
select FEATURE_SYSLOG
|
||||||
help
|
help
|
||||||
init is the first program run when the system boots.
|
init is the first program run when the system boots.
|
||||||
@ -93,7 +92,6 @@ config FEATURE_INITRD
|
|||||||
config HALT
|
config HALT
|
||||||
bool "poweroff, halt, and reboot"
|
bool "poweroff, halt, and reboot"
|
||||||
default y
|
default y
|
||||||
depends on PLATFORM_LINUX
|
|
||||||
help
|
help
|
||||||
Stop all processes and either halt, reboot, or power off the system.
|
Stop all processes and either halt, reboot, or power off the system.
|
||||||
|
|
||||||
|
14
init/halt.c
14
init/halt.c
@ -8,7 +8,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "libbb.h"
|
#include "libbb.h"
|
||||||
#include <sys/reboot.h>
|
#include "reboot.h"
|
||||||
|
|
||||||
#if ENABLE_FEATURE_WTMP
|
#if ENABLE_FEATURE_WTMP
|
||||||
#include <sys/utsname.h>
|
#include <sys/utsname.h>
|
||||||
@ -36,18 +36,6 @@ static void write_wtmp(void)
|
|||||||
#define write_wtmp() ((void)0)
|
#define write_wtmp() ((void)0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef RB_HALT_SYSTEM
|
|
||||||
#define RB_HALT_SYSTEM RB_HALT
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef RB_POWERDOWN
|
|
||||||
/* Stop system and switch power off if possible. */
|
|
||||||
# define RB_POWERDOWN 0x4321fedc
|
|
||||||
#endif
|
|
||||||
#ifndef RB_POWER_OFF
|
|
||||||
# define RB_POWER_OFF RB_POWERDOWN
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
int halt_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
int halt_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||||
int halt_main(int argc UNUSED_PARAM, char **argv)
|
int halt_main(int argc UNUSED_PARAM, char **argv)
|
||||||
|
16
init/init.c
16
init/init.c
@ -12,7 +12,6 @@
|
|||||||
#include "libbb.h"
|
#include "libbb.h"
|
||||||
#include <syslog.h>
|
#include <syslog.h>
|
||||||
#include <paths.h>
|
#include <paths.h>
|
||||||
#include <sys/reboot.h>
|
|
||||||
#include <sys/resource.h>
|
#include <sys/resource.h>
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
#include <linux/vt.h>
|
#include <linux/vt.h>
|
||||||
@ -20,6 +19,7 @@
|
|||||||
#if ENABLE_FEATURE_UTMP
|
#if ENABLE_FEATURE_UTMP
|
||||||
# include <utmp.h> /* DEAD_PROCESS */
|
# include <utmp.h> /* DEAD_PROCESS */
|
||||||
#endif
|
#endif
|
||||||
|
#include "reboot.h" /* reboot() constants */
|
||||||
|
|
||||||
/* Used only for sanitizing purposes in set_sane_term() below. On systems where
|
/* Used only for sanitizing purposes in set_sane_term() below. On systems where
|
||||||
* the baud rate is stored in a separate field, we can safely disable them. */
|
* 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;
|
|||||||
enum {
|
enum {
|
||||||
L_LOG = 0x1,
|
L_LOG = 0x1,
|
||||||
L_CONSOLE = 0x2,
|
L_CONSOLE = 0x2,
|
||||||
#ifndef RB_HALT_SYSTEM
|
|
||||||
RB_HALT_SYSTEM = 0xcdef0123, /* FIXME: this overflows enum */
|
|
||||||
RB_ENABLE_CAD = 0x89abcdef,
|
|
||||||
RB_DISABLE_CAD = 0,
|
|
||||||
RB_POWER_OFF = 0x4321fedc,
|
|
||||||
RB_AUTOBOOT = 0x01234567,
|
|
||||||
#endif
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Print a message to the specified device.
|
/* Print a message to the specified device.
|
||||||
@ -724,10 +717,12 @@ static void restart_handler(int sig UNUSED_PARAM)
|
|||||||
|
|
||||||
run_shutdown_and_kill_processes();
|
run_shutdown_and_kill_processes();
|
||||||
|
|
||||||
|
#ifdef RB_ENABLE_CAD
|
||||||
/* Allow Ctrl-Alt-Del to reboot the system.
|
/* Allow Ctrl-Alt-Del to reboot the system.
|
||||||
* This is how kernel sets it up for init, we follow suit.
|
* This is how kernel sets it up for init, we follow suit.
|
||||||
*/
|
*/
|
||||||
reboot(RB_ENABLE_CAD); /* misnomer */
|
reboot(RB_ENABLE_CAD); /* misnomer */
|
||||||
|
#endif
|
||||||
|
|
||||||
if (open_stdio_to_tty(a->terminal)) {
|
if (open_stdio_to_tty(a->terminal)) {
|
||||||
dbg_message(L_CONSOLE, "Trying to re-exec %s", a->command);
|
dbg_message(L_CONSOLE, "Trying to re-exec %s", a->command);
|
||||||
@ -870,9 +865,11 @@ int init_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
) {
|
) {
|
||||||
bb_show_usage();
|
bb_show_usage();
|
||||||
}
|
}
|
||||||
|
#ifdef RB_DISABLE_CAD
|
||||||
/* Turn off rebooting via CTL-ALT-DEL - we get a
|
/* Turn off rebooting via CTL-ALT-DEL - we get a
|
||||||
* SIGINT on CAD so we can shut things down gracefully... */
|
* SIGINT on CAD so we can shut things down gracefully... */
|
||||||
reboot(RB_DISABLE_CAD); /* misnomer */
|
reboot(RB_DISABLE_CAD); /* misnomer */
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Figure out where the default console should be */
|
/* Figure out where the default console should be */
|
||||||
@ -895,6 +892,8 @@ int init_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
message(L_CONSOLE | L_LOG, "init started: %s", bb_banner);
|
message(L_CONSOLE | L_LOG, "init started: %s", bb_banner);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* struct sysinfo is linux-specific */
|
||||||
|
#ifdef __linux__
|
||||||
/* Make sure there is enough memory to do something useful. */
|
/* Make sure there is enough memory to do something useful. */
|
||||||
if (ENABLE_SWAPONOFF) {
|
if (ENABLE_SWAPONOFF) {
|
||||||
struct sysinfo info;
|
struct sysinfo info;
|
||||||
@ -910,6 +909,7 @@ int init_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
run_actions(SYSINIT); /* wait and removing */
|
run_actions(SYSINIT); /* wait and removing */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Check if we are supposed to be in single user mode */
|
/* Check if we are supposed to be in single user mode */
|
||||||
if (argv[1]
|
if (argv[1]
|
||||||
|
31
init/reboot.h
Normal file
31
init/reboot.h
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* Definitions related to the reboot() system call,
|
||||||
|
* shared between init.c and halt.c.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/reboot.h>
|
||||||
|
|
||||||
|
#ifndef RB_HALT_SYSTEM
|
||||||
|
# if defined(__linux__)
|
||||||
|
# define RB_HALT_SYSTEM 0xcdef0123
|
||||||
|
# define RB_ENABLE_CAD 0x89abcdef
|
||||||
|
# define RB_DISABLE_CAD 0
|
||||||
|
# define RB_POWER_OFF 0x4321fedc
|
||||||
|
# define RB_AUTOBOOT 0x01234567
|
||||||
|
# elif defined(RB_HALT)
|
||||||
|
# define RB_HALT_SYSTEM RB_HALT
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Stop system and switch power off if possible. */
|
||||||
|
#ifndef RB_POWER_OFF
|
||||||
|
# if defined(RB_POWERDOWN)
|
||||||
|
# define RB_POWER_OFF RB_POWERDOWN
|
||||||
|
# elif defined(__linux__)
|
||||||
|
# define RB_POWER_OFF 0x4321fedc
|
||||||
|
# else
|
||||||
|
# warning "poweroff unsupported, using halt as fallback"
|
||||||
|
# define RB_POWER_OFF RB_HALT_SYSTEM
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user