[BusyBox-cvs] busybox/init init_shared.c,NONE,1.1 init_shared.h,NONE,1.1 Makefile.in,1.4,1.5 halt.c,1.20,1.21 init.c,1.184,1.185 poweroff.c,1.17,1.18 reboot.c,1.26,1.27

Erik Andersen andersen at busybox.net
Fri Jun 27 17:08:21 UTC 2003


Update of /var/cvs/busybox/init
In directory winder:/tmp/cvs-serv29580/init

Modified Files:
	Makefile.in halt.c init.c poweroff.c reboot.c 
Added Files:
	init_shared.c init_shared.h 
Log Message:
Apply last_patch93 from vodz:

    andersen at 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



--- NEW FILE: init_shared.c ---
#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
}

--- NEW FILE: init_shared.h ---
extern int kill_init(int sig);

Index: Makefile.in
===================================================================
RCS file: /var/cvs/busybox/init/Makefile.in,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- Makefile.in	11 May 2003 14:52:39 -0000	1.4
+++ Makefile.in	27 Jun 2003 17:08:15 -0000	1.5
@@ -33,6 +33,28 @@
 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))

Index: halt.c
===================================================================
RCS file: /var/cvs/busybox/init/halt.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -d -r1.20 -r1.21
--- halt.c	19 Mar 2003 09:11:57 -0000	1.20
+++ halt.c	27 Jun 2003 17:08:15 -0000	1.21
@@ -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);
 }

Index: init.c
===================================================================
RCS file: /var/cvs/busybox/init/init.c,v
retrieving revision 1.184
retrieving revision 1.185
diff -u -d -r1.184 -r1.185
--- init.c	27 Jun 2003 05:46:29 -0000	1.184
+++ init.c	27 Jun 2003 17:08:15 -0000	1.185
@@ -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 @@
 
 /* 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 @@
 	/* 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 @@
 	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 */
@@ -1048,9 +1043,6 @@
 	 * SIGINT on CAD so we can shut things down gracefully... */
 	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();

Index: poweroff.c
===================================================================
RCS file: /var/cvs/busybox/init/poweroff.c,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- poweroff.c	19 Mar 2003 09:11:57 -0000	1.17
+++ poweroff.c	27 Jun 2003 17:08:15 -0000	1.18
@@ -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);
 }

Index: reboot.c
===================================================================
RCS file: /var/cvs/busybox/init/reboot.c,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -d -r1.26 -r1.27
--- reboot.c	19 Mar 2003 09:11:57 -0000	1.26
+++ reboot.c	27 Jun 2003 17:08:15 -0000	1.27
@@ -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 @@
 
 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 @@
 		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 */
-#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));
-	}
+		return 0; /* Shrug */
 #else
-	return(kill(1, SIGTERM));
-#endif
+	return kill_init(SIGTERM);
 #endif
 }
 



More information about the busybox-cvs mailing list