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.
This commit is contained in:
Denis Vlasenko 2008-03-17 22:01:42 +00:00
parent 2724fa9d8a
commit e421b5ebf6

View File

@ -214,8 +214,7 @@ static void console_init(void)
if (fd >= 0) { if (fd >= 0) {
dup2(fd, 0); dup2(fd, 0);
dup2(fd, 1); dup2(fd, 1);
dup2(fd, 2); xmove_fd(fd, 2);
while (fd > 2) close(fd--);
} }
messageD(L_LOG, "console='%s'", s); messageD(L_LOG, "console='%s'", s);
} else { } else {
@ -223,7 +222,7 @@ static void console_init(void)
* (so that they won't be used by future opens) */ * (so that they won't be used by future opens) */
/* bb_sanitize_stdio(); - WRONG. /* 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. */ * this is a real possibility! Open code it instead. */
int fd = open(bb_dev_null, O_RDWR); int fd = open(bb_dev_null, O_RDWR);
@ -234,11 +233,11 @@ static void console_init(void)
while ((unsigned)fd < 2) while ((unsigned)fd < 2)
fd = dup(fd); fd = dup(fd);
if (fd > 2) if (fd > 2)
close (fd); close(fd);
} }
s = getenv("TERM"); 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 /* Force the TERM setting to vt102 for serial console
* if TERM is set to linux (the default) */ * if TERM is set to linux (the default) */
if (!s || strcmp(s, "linux") == 0) if (!s || strcmp(s, "linux") == 0)