aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2003-06-27 17:08:15 +0000
committerEric Andersen <andersen@codepoet.org>2003-06-27 17:08:15 +0000
commitb01ed65ad2e46fc7747010b16e53b3a9e1a7c23a (patch)
tree2988261cdc1078ca34f71822d101aab5b482df43
parent0b0d393347a2f4444a49afa32491068ac92cbfa3 (diff)
downloadbusybox-w32-b01ed65ad2e46fc7747010b16e53b3a9e1a7c23a.tar.gz
busybox-w32-b01ed65ad2e46fc7747010b16e53b3a9e1a7c23a.tar.bz2
busybox-w32-b01ed65ad2e46fc7747010b16e53b3a9e1a7c23a.zip
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
-rw-r--r--init/Makefile.in22
-rw-r--r--init/halt.c15
-rw-r--r--init/init.c20
-rw-r--r--init/init_shared.c21
-rw-r--r--init/init_shared.h1
-rw-r--r--init/poweroff.c13
-rw-r--r--init/reboot.c42
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
33INIT-$(CONFIG_REBOOT) += reboot.o 33INIT-$(CONFIG_REBOOT) += reboot.o
34INIT-$(CONFIG_START_STOP_DAEMON) += start_stop_daemon.o 34INIT-$(CONFIG_START_STOP_DAEMON) += start_stop_daemon.o
35 35
36ifeq ($(CONFIG_HALT), y)
37CONFIG_INIT_SHARED=y
38else
39ifeq ($(CONFIG_INIT), y)
40CONFIG_INIT_SHARED=y
41else
42ifeq ($(CONFIG_POWEROFF), y)
43CONFIG_INIT_SHARED=y
44else
45ifeq ($(CONFIG_REBOOT), y)
46CONFIG_INIT_SHARED=y
47else
48CONFIG_INIT_SHARED=n
49endif
50endif
51endif
52endif
53
54ifeq ($(CONFIG_INIT_SHARED), y)
55INIT-$(CONFIG_INIT_SHARED) += init_shared.o
56endif
57
36libraries-y+=$(INIT_DIR)$(INIT_AR) 58libraries-y+=$(INIT_DIR)$(INIT_AR)
37 59
38$(INIT_DIR)$(INIT_AR): $(patsubst %,$(INIT_DIR)%, $(INIT-y)) 60$(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 @@
23 23
24#include "busybox.h" 24#include "busybox.h"
25#include <signal.h> 25#include <signal.h>
26#include "init_shared.h"
27
26 28
27extern int halt_main(int argc, char **argv) 29extern int halt_main(int argc, char **argv)
28{ 30{
29#ifdef CONFIG_FEATURE_INITRD 31 return kill_init(SIGUSR1);
30 /* don't assume init's pid == 1 */
31 long *pid = find_pid_by_name("init");
32 if (!pid || *pid<=0) {
33 pid = find_pid_by_name("linuxrc");
34 if (!pid || *pid<=0)
35 bb_error_msg_and_die("no process killed");
36 }
37 return(kill(*pid, SIGUSR1));
38#else
39 return(kill(1, SIGUSR1));
40#endif
41} 32}
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 @@
43#include <sys/types.h> 43#include <sys/types.h>
44#include <sys/wait.h> 44#include <sys/wait.h>
45#include "busybox.h" 45#include "busybox.h"
46
47#include "init_shared.h"
48
49
46#ifdef CONFIG_SYSLOGD 50#ifdef CONFIG_SYSLOGD
47# include <sys/syslog.h> 51# include <sys/syslog.h>
48#endif 52#endif
@@ -152,7 +156,6 @@ struct init_action {
152 156
153/* Static variables */ 157/* Static variables */
154static struct init_action *init_action_list = NULL; 158static struct init_action *init_action_list = NULL;
155static int kernelVersion;
156static char console[CONSOLE_BUFF_SIZE] = _PATH_CONSOLE; 159static char console[CONSOLE_BUFF_SIZE] = _PATH_CONSOLE;
157 160
158#ifndef CONFIG_SYSLOGD 161#ifndef CONFIG_SYSLOGD
@@ -764,7 +767,7 @@ static void halt_signal(int sig)
764 /* allow time for last message to reach serial console */ 767 /* allow time for last message to reach serial console */
765 sleep(2); 768 sleep(2);
766 769
767 if (sig == SIGUSR2 && kernelVersion >= KERNEL_VERSION(2, 2, 0)) 770 if (sig == SIGUSR2)
768 init_reboot(RB_POWER_OFF); 771 init_reboot(RB_POWER_OFF);
769 else 772 else
770 init_reboot(RB_HALT_SYSTEM); 773 init_reboot(RB_HALT_SYSTEM);
@@ -1014,15 +1017,7 @@ extern int init_main(int argc, char **argv)
1014 int status; 1017 int status;
1015 1018
1016 if (argc > 1 && !strcmp(argv[1], "-q")) { 1019 if (argc > 1 && !strcmp(argv[1], "-q")) {
1017 /* don't assume init's pid == 1 */ 1020 return kill_init(SIGHUP);
1018 long *pid = find_pid_by_name("init");
1019
1020 if (!pid || *pid <= 0) {
1021 pid = find_pid_by_name("linuxrc");
1022 if (!pid || *pid <= 0)
1023 bb_error_msg_and_die("no process killed");
1024 }
1025 return kill(*pid, SIGHUP);
1026 } 1021 }
1027#ifndef DEBUG_INIT 1022#ifndef DEBUG_INIT
1028 /* Expect to be invoked as init with PID=1 or be invoked as linuxrc */ 1023 /* 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)
1049 init_reboot(RB_DISABLE_CAD); 1044 init_reboot(RB_DISABLE_CAD);
1050#endif 1045#endif
1051 1046
1052 /* Figure out what kernel this is running */
1053 kernelVersion = get_kernel_revision();
1054
1055 /* Figure out where the default console should be */ 1047 /* Figure out where the default console should be */
1056 console_init(); 1048 console_init();
1057 1049
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 @@
1#include <signal.h>
2#include "busybox.h"
3
4#include "init_shared.h"
5
6
7extern int kill_init(int sig)
8{
9#ifdef CONFIG_FEATURE_INITRD
10 /* don't assume init's pid == 1 */
11 long *pid = find_pid_by_name("init");
12 if (!pid || *pid<=0) {
13 pid = find_pid_by_name("linuxrc");
14 if (!pid || *pid<=0)
15 bb_error_msg_and_die("no process killed");
16 }
17 return(kill(*pid, sig));
18#else
19 return(kill(1, sig));
20#endif
21}
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 @@
26 26
27extern int poweroff_main(int argc, char **argv) 27extern int poweroff_main(int argc, char **argv)
28{ 28{
29#ifdef CONFIG_FEATURE_INITRD 29 return kill_init(SIGUSR2);
30 /* don't assume init's pid == 1 */
31 long *pid = find_pid_by_name("init");
32 if (!pid || *pid<=0) {
33 pid = find_pid_by_name("linuxrc");
34 if (!pid || *pid<=0)
35 bb_error_msg_and_die("no process killed");
36 }
37 return(kill(*pid, SIGUSR2));
38#else
39 return(kill(1, SIGUSR2));
40#endif
41} 30}
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 @@
27#include <getopt.h> 27#include <getopt.h>
28 28
29#include "busybox.h" 29#include "busybox.h"
30#include "init_shared.h"
31
30 32
31#if (__GNU_LIBRARY__ > 5) || defined(__dietlibc__) 33#if (__GNU_LIBRARY__ > 5) || defined(__dietlibc__)
32 #include <sys/reboot.h> 34 #include <sys/reboot.h>
@@ -42,24 +44,12 @@ static const int RB_AUTOBOOT = 0x01234567;
42 44
43extern int reboot_main(int argc, char **argv) 45extern int reboot_main(int argc, char **argv)
44{ 46{
45 int delay = 0; /* delay in seconds before rebooting */ 47 char *delay; /* delay in seconds before rebooting */
46 int rc;
47
48 while ((rc = getopt(argc, argv, "d:")) > 0) {
49 switch (rc) {
50 case 'd':
51 delay = atoi(optarg);
52 break;
53 48
54 default: 49 if(bb_getopt_ulflags(argc, argv, "d:", &delay)) {
55 bb_show_usage(); 50 sleep(atoi(delay));
56 break;
57 }
58 } 51 }
59 52
60 if(delay > 0)
61 sleep(delay);
62
63#ifdef CONFIG_USER_INIT 53#ifdef CONFIG_USER_INIT
64 /* Don't kill ourself */ 54 /* Don't kill ourself */
65 signal(SIGTERM,SIG_IGN); 55 signal(SIGTERM,SIG_IGN);
@@ -83,29 +73,11 @@ extern int reboot_main(int argc, char **argv)
83 sleep(1); 73 sleep(1);
84 74
85 sync(); 75 sync();
86 if (kernelVersion > 0 && kernelVersion <= KERNEL_VERSION(2,2,11)) {
87 /* bdflush, kupdate not needed for kernels >2.2.11 */
88 bdflush(1, 0);
89 sync();
90 }
91 76
92 init_reboot(RB_AUTOBOOT); 77 init_reboot(RB_AUTOBOOT);
93 exit(0); /* Shrug */ 78 return 0; /* Shrug */
94#else 79#else
95#ifdef CONFIG_FEATURE_INITRD 80 return kill_init(SIGTERM);
96 {
97 /* don't assume init's pid == 1 */
98 long *pid = find_pid_by_name("init");
99 if (!pid || *pid<=0)
100 pid = find_pid_by_name("linuxrc");
101 if (!pid || *pid<=0)
102 bb_error_msg_and_die("no process killed");
103 fflush(stdout);
104 return(kill(*pid, SIGTERM));
105 }
106#else
107 return(kill(1, SIGTERM));
108#endif
109#endif 81#endif
110} 82}
111 83