svn commit: trunk/busybox: init miscutils networking

vda at busybox.net vda at busybox.net
Sat Sep 20 16:29:00 UTC 2008


Author: vda
Date: 2008-09-20 09:28:59 -0700 (Sat, 20 Sep 2008)
New Revision: 23446

Log:
init: set stderr to NONBLOCK
*: s/setenv(a,b,1)/xsetenv(a,b)/

function                                             old     new   delta
init_main                                            856     895     +39
message                                              146     144      -2
crond_main                                          1418    1416      -2
run                                                  661     658      -3
zcip_main                                           1409    1403      -6
edit_file                                            910     901      -9
environment                                           20       -     -20



Modified:
   trunk/busybox/init/init.c
   trunk/busybox/miscutils/crond.c
   trunk/busybox/miscutils/crontab.c
   trunk/busybox/networking/zcip.c


Changeset:
Modified: trunk/busybox/init/init.c
===================================================================
--- trunk/busybox/init/init.c	2008-09-20 15:16:50 UTC (rev 23445)
+++ trunk/busybox/init/init.c	2008-09-20 16:28:59 UTC (rev 23446)
@@ -77,14 +77,6 @@
 #endif
 };
 
-static const char *const environment[] = {
-	"HOME=/",
-	bb_PATH_root_path,
-	"SHELL=/bin/sh",
-	"USER=root",
-	NULL
-};
-
 /* Function prototypes */
 static void halt_reboot_pwoff(int sig) NORETURN;
 
@@ -118,15 +110,16 @@
 {
 	static int log_fd = -1;
 	va_list arguments;
-	int l;
+	unsigned l;
 	char msg[128];
 
 	msg[0] = '\r';
 	va_start(arguments, fmt);
-	vsnprintf(msg + 1, sizeof(msg) - 2, fmt, arguments);
+	l = vsnprintf(msg + 1, sizeof(msg) - 2, fmt, arguments);
+	if (l > sizeof(msg) - 2)
+		l = sizeof(msg) - 2;
+	msg[l] = '\0';
 	va_end(arguments);
-	msg[sizeof(msg) - 2] = '\0';
-	l = strlen(msg);
 
 	if (ENABLE_FEATURE_INIT_SYSLOG) {
 		/* Log the message to syslogd */
@@ -213,6 +206,8 @@
 		/* Make sure fd 0,1,2 are not closed
 		 * (so that they won't be used by future opens) */
 		bb_sanitize_stdio();
+		/* Make sure init can't be blocked by writing to stderr */
+		fcntl(STDERR_FILENO, F_SETFL, fcntl(STDERR_FILENO, F_GETFL) | O_NONBLOCK);
 	}
 
 	s = getenv("TERM");
@@ -825,15 +820,15 @@
 	set_sane_term();
 	xchdir("/");
 	setsid();
-	{
-		const char *const *e;
-		/* Make sure environs is set to something sane */
-		for (e = environment; *e; e++)
-			putenv((char *) *e);
-	}
 
+	/* Make sure environs is set to something sane */
+	putenv((char *) "HOME=/");
+	putenv((char *) bb_PATH_root_path);
+	putenv((char *) "SHELL=/bin/sh");
+	putenv((char *) "USER=root"); /* needed? why? */
+
 	if (argv[1])
-		setenv("RUNLEVEL", argv[1], 1);
+		xsetenv("RUNLEVEL", argv[1]);
 
 	/* Hello world */
 	message(MAYBE_CONSOLE | L_LOG, "init started: %s", bb_banner);

Modified: trunk/busybox/miscutils/crond.c
===================================================================
--- trunk/busybox/miscutils/crond.c	2008-09-20 15:16:50 UTC (rev 23445)
+++ trunk/busybox/miscutils/crond.c	2008-09-20 16:28:59 UTC (rev 23446)
@@ -187,7 +187,7 @@
 
 	xchdir(CDir);
 	//signal(SIGHUP, SIG_IGN); /* ? original crond dies on HUP... */
-	setenv("SHELL", DEFAULT_SHELL, 1); /* once, for all future children */
+	xsetenv("SHELL", DEFAULT_SHELL); /* once, for all future children */
 	crondlog(LVL9 "crond (busybox "BB_VER") started, log level %d", LogLevel);
 	SynchronizeDir();
 
@@ -275,8 +275,8 @@
 	/* if we want to set user's shell instead: */
 	/*safe_setenv(env_var_user, "SHELL", pas->pw_shell, 5);*/
 #else
-	setenv("USER", pas->pw_name, 1);
-	setenv("HOME", pas->pw_dir, 1);
+	xsetenv("USER", pas->pw_name);
+	xsetenv("HOME", pas->pw_dir);
 #endif
 	/* currently, we use constant one: */
 	/*setenv("SHELL", DEFAULT_SHELL, 1); - done earlier */

Modified: trunk/busybox/miscutils/crontab.c
===================================================================
--- trunk/busybox/miscutils/crontab.c	2008-09-20 15:16:50 UTC (rev 23445)
+++ trunk/busybox/miscutils/crontab.c	2008-09-20 16:28:59 UTC (rev 23446)
@@ -21,9 +21,9 @@
 
 static void change_user(const struct passwd *pas)
 {
-	setenv("USER", pas->pw_name, 1);
-	setenv("HOME", pas->pw_dir, 1);
-	setenv("SHELL", DEFAULT_SHELL, 1);
+	xsetenv("USER", pas->pw_name);
+	xsetenv("HOME", pas->pw_dir);
+	xsetenv("SHELL", DEFAULT_SHELL);
 
 	/* initgroups, setgid, setuid */
 	change_identity(pas);

Modified: trunk/busybox/networking/zcip.c
===================================================================
--- trunk/busybox/networking/zcip.c	2008-09-20 15:16:50 UTC (rev 23445)
+++ trunk/busybox/networking/zcip.c	2008-09-20 16:28:59 UTC (rev 23446)
@@ -144,7 +144,7 @@
 
 	if (ip) {
 		addr = inet_ntoa(*ip);
-		setenv("ip", addr, 1);
+		xsetenv("ip", addr);
 		fmt -= 3;
 	}
 	bb_info_msg(fmt, argv[1], intf, addr);
@@ -238,7 +238,7 @@
 
 	intf = argv[0];
 	script_av[0] = argv[1];
-	setenv("interface", intf, 1);
+	xsetenv("interface", intf);
 
 	// initialize the interface (modprobe, ifup, etc)
 	script_av[1] = (char*)"init";




More information about the busybox-cvs mailing list