diff options
author | Eric Andersen <andersen@codepoet.org> | 2003-06-27 21:08:15 +0400 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2003-06-27 21:08:15 +0400 |
commit | b01ed65ad2e46fc7747010b16e53b3a9e1a7c23a (patch) | |
tree | 2988261cdc1078ca34f71822d101aab5b482df43 /init | |
parent | 0b0d393347a2f4444a49afa32491068ac92cbfa3 (diff) |
Apply last_patch93 from vodz:
andersen@busybox.net wrote:
>Message: 4
>Modified Files:
> init.c
>Log Message:
>Remove code for unsupported kernel versions
Hmm. Current init.c have check >= 2.2.0 kernel one time too.
Ok. Last patch removed this point and move common init code to new file for
/init dir
Diffstat (limited to 'init')
-rw-r--r-- | init/Makefile.in | 22 | ||||
-rw-r--r-- | init/halt.c | 15 | ||||
-rw-r--r-- | init/init.c | 20 | ||||
-rw-r--r-- | init/init_shared.c | 21 | ||||
-rw-r--r-- | init/init_shared.h | 1 | ||||
-rw-r--r-- | init/poweroff.c | 13 | ||||
-rw-r--r-- | init/reboot.c | 42 |
7 files changed, 61 insertions, 73 deletions
diff --git a/init/Makefile.in b/init/Makefile.in index 9e2f4bcf7..1eee3d18a 100644 --- a/init/Makefile.in +++ b/init/Makefile.in @@ -33,6 +33,28 @@ INIT-$(CONFIG_POWEROFF) += poweroff.o 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)) diff --git a/init/halt.c b/init/halt.c index 7e663227c..b9eeaebdd 100644 --- a/init/halt.c +++ b/init/halt.c @@ -23,19 +23,10 @@ #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); } diff --git a/init/init.c b/init/init.c index d51d29156..1667d58cf 100644 --- a/init/init.c +++ b/init/init.c @@ -43,6 +43,10 @@ #include <sys/types.h> #include <sys/wait.h> #include "busybox.h" + +#include "init_shared.h" + + #ifdef CONFIG_SYSLOGD # include <sys/syslog.h> #endif @@ -152,7 +156,6 @@ struct init_action { /* Static variables */ static struct init_action *init_action_list = NULL; -static int kernelVersion; static char console[CONSOLE_BUFF_SIZE] = _PATH_CONSOLE; #ifndef CONFIG_SYSLOGD @@ -764,7 +767,7 @@ static void halt_signal(int sig) /* 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); @@ -1014,15 +1017,7 @@ extern int init_main(int argc, char **argv) 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 */ @@ -1049,9 +1044,6 @@ extern int init_main(int argc, char **argv) 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(); diff --git a/init/init_shared.c b/init/init_shared.c new file mode 100644 index 000000000..842942fe3 --- /dev/null +++ b/init/init_shared.c @@ -0,0 +1,21 @@ +#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 +} diff --git a/init/init_shared.h b/init/init_shared.h new file mode 100644 index 000000000..d10a1bd3b --- /dev/null +++ b/init/init_shared.h @@ -0,0 +1 @@ +extern int kill_init(int sig); diff --git a/init/poweroff.c b/init/poweroff.c index aca6e2f25..d78ff4f98 100644 --- a/init/poweroff.c +++ b/init/poweroff.c @@ -26,16 +26,5 @@ 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); } diff --git a/init/reboot.c b/init/reboot.c index 8c380fa6a..be4b97f95 100644 --- a/init/reboot.c +++ b/init/reboot.c @@ -27,6 +27,8 @@ #include <getopt.h> #include "busybox.h" +#include "init_shared.h" + #if (__GNU_LIBRARY__ > 5) || defined(__dietlibc__) #include <sys/reboot.h> @@ -42,24 +44,12 @@ static const int RB_AUTOBOOT = 0x01234567; 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); @@ -83,29 +73,11 @@ extern int reboot_main(int argc, char **argv) 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 } |