svn commit: trunk/busybox: init

aldot at busybox.net aldot at busybox.net
Mon May 29 12:54:18 UTC 2006


Author: aldot
Date: 2006-05-29 05:54:16 -0700 (Mon, 29 May 2006)
New Revision: 15220

Log:
- move common code into new open_new_terminal() function;
   text    data     bss     dec     hex filename
 864434   10244  645892 1520570  1733ba busybox_old
 864386   10244  645892 1520522  17338a busybox_unstripped

add/remove: 1/0 grow/shrink: 0/2 up/down: 92/-143 (-51)
function                                     old     new   delta
open_new_terminal                              -      92     +92
exec_signal                                  345     276     -69
run                                         1527    1453     -74
Again, 48 != 51 so let's trust the former..


Modified:
   trunk/busybox/TODO
   trunk/busybox/init/init.c


Changeset:
Modified: trunk/busybox/TODO
===================================================================
--- trunk/busybox/TODO	2006-05-29 12:12:45 UTC (rev 15219)
+++ trunk/busybox/TODO	2006-05-29 12:54:16 UTC (rev 15220)
@@ -27,7 +27,7 @@
   bzip2
     Compression-side support.
   init
-    General cleanup.
+    General cleanup (should use ENABLE_FEATURE_INIT_SYSLOG and ENABLE_FEATURE_INIT_DEBUG).
   Unify base64 handling.
     There's base64 encoding and decoding going on in:
       networking/wget.c:base64enc()

Modified: trunk/busybox/init/init.c
===================================================================
--- trunk/busybox/init/init.c	2006-05-29 12:12:45 UTC (rev 15219)
+++ trunk/busybox/init/init.c	2006-05-29 12:54:16 UTC (rev 15220)
@@ -386,6 +386,23 @@
 	}
 }
 
+/* Open the new terminal device */
+static void open_new_terminal(const char *device, char fail) {
+	struct stat sb;
+
+	if ((device_open(device, O_RDWR)) < 0) {
+		if (stat(device, &sb) != 0) {
+			message(LOG | CONSOLE, "device '%s' does not exist.", device);
+		} else {
+			message(LOG | CONSOLE, "Bummer, can't open %s", device);
+		}
+		if (fail)
+			_exit(1);
+		/* else */
+		halt_signal(SIGUSR1);
+	}
+}
+
 static pid_t run(const struct init_action *a)
 {
 	int i, junk;
@@ -405,7 +422,6 @@
 	sigprocmask(SIG_BLOCK, &nmask, &omask);
 
 	if ((pid = fork()) == 0) {
-		struct stat sb;
 
 		/* Clean up */
 		close(0);
@@ -429,14 +445,7 @@
 		setsid();
 
 		/* Open the new terminal device */
-		if ((device_open(a->terminal, O_RDWR)) < 0) {
-			if (stat(a->terminal, &sb) != 0) {
-				message(LOG | CONSOLE, "device '%s' does not exist.", a->terminal);
-			} else {
-				message(LOG | CONSOLE, "Bummer, can't open %s", a->terminal);
-			}
-			_exit(1);
-		}
+		open_new_terminal(a->terminal, 1);
 
 		/* Make sure the terminal will act fairly normal for us */
 		set_term(0);
@@ -575,12 +584,15 @@
 				  getpid(), a->terminal, cmdpath);
 
 #if defined CONFIG_FEATURE_INIT_COREDUMPS
-		if (stat(CORE_ENABLE_FLAG_FILE, &sb) == 0) {
-			struct rlimit limit;
+		{
+			struct stat sb;
+			if (stat(CORE_ENABLE_FLAG_FILE, &sb) == 0) {
+				struct rlimit limit;
 
-			limit.rlim_cur = RLIM_INFINITY;
-			limit.rlim_max = RLIM_INFINITY;
-			setrlimit(RLIMIT_CORE, &limit);
+				limit.rlim_cur = RLIM_INFINITY;
+				limit.rlim_max = RLIM_INFINITY;
+				setrlimit(RLIMIT_CORE, &limit);
+			}
 		}
 #endif
 
@@ -729,15 +741,7 @@
 			close(2);
 
 			/* Open the new terminal device */
-			if ((device_open(a->terminal, O_RDWR)) < 0) {
-				struct stat sb;
-				if (stat(a->terminal, &sb) != 0) {
-					message(LOG | CONSOLE, "device '%s' does not exist.", a->terminal);
-				} else {
-					message(LOG | CONSOLE, "Bummer, can't open %s", a->terminal);
-				}
-				halt_signal(SIGUSR1);
-			}
+			open_new_terminal(a->terminal, 0);
 
 			/* Make sure the terminal will act fairly normal for us */
 			set_term(0);




More information about the busybox-cvs mailing list