svn commit: trunk/busybox/init

vda at busybox.net vda at busybox.net
Mon Mar 17 22:01:43 UTC 2008


Author: vda
Date: 2008-03-17 15:01:42 -0700 (Mon, 17 Mar 2008)
New Revision: 21371

Log:
init: do not close all descriptors > 2. We were doing it - sometimes.
Good choices are "do it, always" or "don't do it". Second is smaller.



Modified:
   trunk/busybox/init/init.c


Changeset:
Modified: trunk/busybox/init/init.c
===================================================================
--- trunk/busybox/init/init.c	2008-03-17 19:44:43 UTC (rev 21370)
+++ trunk/busybox/init/init.c	2008-03-17 22:01:42 UTC (rev 21371)
@@ -214,8 +214,7 @@
 		if (fd >= 0) {
 			dup2(fd, 0);
 			dup2(fd, 1);
-			dup2(fd, 2);
-			while (fd > 2) close(fd--);
+			xmove_fd(fd, 2);
 		}
 		messageD(L_LOG, "console='%s'", s);
 	} else {
@@ -223,7 +222,7 @@
 		 * (so that they won't be used by future opens) */
 
 		/* bb_sanitize_stdio(); - WRONG.
-		 * Fail if "/dev/null" doesnt exist, and for init
+		 * It fails if "/dev/null" doesnt exist, and for init
 		 * this is a real possibility! Open code it instead. */
 
 		int fd = open(bb_dev_null, O_RDWR);
@@ -234,11 +233,11 @@
     		while ((unsigned)fd < 2)
             		fd = dup(fd);
 		if (fd > 2)
-			close (fd);
+			close(fd);
 	}
 
 	s = getenv("TERM");
-	if (ioctl(0, TIOCGSERIAL, &sr) == 0) {
+	if (ioctl(STDIN_FILENO, TIOCGSERIAL, &sr) == 0) {
 		/* Force the TERM setting to vt102 for serial console
 		 * if TERM is set to linux (the default) */
 		if (!s || strcmp(s, "linux") == 0)




More information about the busybox-cvs mailing list