INIT-$(CONFIG_REBOOT) += reboot.o
INIT-$(CONFIG_START_STOP_DAEMON) += start_stop_daemon.o
+ifeq ($(CONFIG_HALT), y)
+CONFIG_INIT_SHARED=y
+else
+ifeq ($(CONFIG_INIT), y)
+CONFIG_INIT_SHARED=y
+else
+ifeq ($(CONFIG_POWEROFF), y)
+CONFIG_INIT_SHARED=y
+else
+ifeq ($(CONFIG_REBOOT), y)
+CONFIG_INIT_SHARED=y
+else
+CONFIG_INIT_SHARED=n
+endif
+endif
+endif
+endif
+
+ifeq ($(CONFIG_INIT_SHARED), y)
+INIT-$(CONFIG_INIT_SHARED) += init_shared.o
+endif
+
libraries-y+=$(INIT_DIR)$(INIT_AR)
$(INIT_DIR)$(INIT_AR): $(patsubst %,$(INIT_DIR)%, $(INIT-y))
#include "busybox.h"
#include <signal.h>
+#include "init_shared.h"
+
extern int halt_main(int argc, char **argv)
{
-#ifdef CONFIG_FEATURE_INITRD
- /* don't assume init's pid == 1 */
- long *pid = find_pid_by_name("init");
- if (!pid || *pid<=0) {
- pid = find_pid_by_name("linuxrc");
- if (!pid || *pid<=0)
- bb_error_msg_and_die("no process killed");
- }
- return(kill(*pid, SIGUSR1));
-#else
- return(kill(1, SIGUSR1));
-#endif
+ return kill_init(SIGUSR1);
}
#include <sys/types.h>
#include <sys/wait.h>
#include "busybox.h"
+
+#include "init_shared.h"
+
+
#ifdef CONFIG_SYSLOGD
# include <sys/syslog.h>
#endif
/* Static variables */
static struct init_action *init_action_list = NULL;
-static int kernelVersion;
static char console[CONSOLE_BUFF_SIZE] = _PATH_CONSOLE;
#ifndef CONFIG_SYSLOGD
/* allow time for last message to reach serial console */
sleep(2);
- if (sig == SIGUSR2 && kernelVersion >= KERNEL_VERSION(2, 2, 0))
+ if (sig == SIGUSR2)
init_reboot(RB_POWER_OFF);
else
init_reboot(RB_HALT_SYSTEM);
int status;
if (argc > 1 && !strcmp(argv[1], "-q")) {
- /* don't assume init's pid == 1 */
- long *pid = find_pid_by_name("init");
-
- if (!pid || *pid <= 0) {
- pid = find_pid_by_name("linuxrc");
- if (!pid || *pid <= 0)
- bb_error_msg_and_die("no process killed");
- }
- return kill(*pid, SIGHUP);
+ return kill_init(SIGHUP);
}
#ifndef DEBUG_INIT
/* Expect to be invoked as init with PID=1 or be invoked as linuxrc */
init_reboot(RB_DISABLE_CAD);
#endif
- /* Figure out what kernel this is running */
- kernelVersion = get_kernel_revision();
-
/* Figure out where the default console should be */
console_init();
--- /dev/null
+#include <signal.h>
+#include "busybox.h"
+
+#include "init_shared.h"
+
+
+extern int kill_init(int sig)
+{
+#ifdef CONFIG_FEATURE_INITRD
+ /* don't assume init's pid == 1 */
+ long *pid = find_pid_by_name("init");
+ if (!pid || *pid<=0) {
+ pid = find_pid_by_name("linuxrc");
+ if (!pid || *pid<=0)
+ bb_error_msg_and_die("no process killed");
+ }
+ return(kill(*pid, sig));
+#else
+ return(kill(1, sig));
+#endif
+}
--- /dev/null
+extern int kill_init(int sig);
extern int poweroff_main(int argc, char **argv)
{
-#ifdef CONFIG_FEATURE_INITRD
- /* don't assume init's pid == 1 */
- long *pid = find_pid_by_name("init");
- if (!pid || *pid<=0) {
- pid = find_pid_by_name("linuxrc");
- if (!pid || *pid<=0)
- bb_error_msg_and_die("no process killed");
- }
- return(kill(*pid, SIGUSR2));
-#else
- return(kill(1, SIGUSR2));
-#endif
+ return kill_init(SIGUSR2);
}
#include <getopt.h>
#include "busybox.h"
+#include "init_shared.h"
+
#if (__GNU_LIBRARY__ > 5) || defined(__dietlibc__)
#include <sys/reboot.h>
extern int reboot_main(int argc, char **argv)
{
- int delay = 0; /* delay in seconds before rebooting */
- int rc;
-
- while ((rc = getopt(argc, argv, "d:")) > 0) {
- switch (rc) {
- case 'd':
- delay = atoi(optarg);
- break;
+ char *delay; /* delay in seconds before rebooting */
- default:
- bb_show_usage();
- break;
- }
+ if(bb_getopt_ulflags(argc, argv, "d:", &delay)) {
+ sleep(atoi(delay));
}
- if(delay > 0)
- sleep(delay);
-
#ifdef CONFIG_USER_INIT
/* Don't kill ourself */
signal(SIGTERM,SIG_IGN);
sleep(1);
sync();
- if (kernelVersion > 0 && kernelVersion <= KERNEL_VERSION(2,2,11)) {
- /* bdflush, kupdate not needed for kernels >2.2.11 */
- bdflush(1, 0);
- sync();
- }
init_reboot(RB_AUTOBOOT);
- exit(0); /* Shrug */
+ return 0; /* Shrug */
#else
-#ifdef CONFIG_FEATURE_INITRD
- {
- /* don't assume init's pid == 1 */
- long *pid = find_pid_by_name("init");
- if (!pid || *pid<=0)
- pid = find_pid_by_name("linuxrc");
- if (!pid || *pid<=0)
- bb_error_msg_and_die("no process killed");
- fflush(stdout);
- return(kill(*pid, SIGTERM));
- }
-#else
- return(kill(1, SIGTERM));
-#endif
+ return kill_init(SIGTERM);
#endif
}