diff options
-rw-r--r-- | init/init.c | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/init/init.c b/init/init.c index eefb9df55..c4674a55f 100644 --- a/init/init.c +++ b/init/init.c | |||
@@ -214,8 +214,7 @@ static void console_init(void) | |||
214 | if (fd >= 0) { | 214 | if (fd >= 0) { |
215 | dup2(fd, 0); | 215 | dup2(fd, 0); |
216 | dup2(fd, 1); | 216 | dup2(fd, 1); |
217 | dup2(fd, 2); | 217 | xmove_fd(fd, 2); |
218 | while (fd > 2) close(fd--); | ||
219 | } | 218 | } |
220 | messageD(L_LOG, "console='%s'", s); | 219 | messageD(L_LOG, "console='%s'", s); |
221 | } else { | 220 | } else { |
@@ -223,7 +222,7 @@ static void console_init(void) | |||
223 | * (so that they won't be used by future opens) */ | 222 | * (so that they won't be used by future opens) */ |
224 | 223 | ||
225 | /* bb_sanitize_stdio(); - WRONG. | 224 | /* bb_sanitize_stdio(); - WRONG. |
226 | * Fail if "/dev/null" doesnt exist, and for init | 225 | * It fails if "/dev/null" doesnt exist, and for init |
227 | * this is a real possibility! Open code it instead. */ | 226 | * this is a real possibility! Open code it instead. */ |
228 | 227 | ||
229 | int fd = open(bb_dev_null, O_RDWR); | 228 | int fd = open(bb_dev_null, O_RDWR); |
@@ -234,11 +233,11 @@ static void console_init(void) | |||
234 | while ((unsigned)fd < 2) | 233 | while ((unsigned)fd < 2) |
235 | fd = dup(fd); | 234 | fd = dup(fd); |
236 | if (fd > 2) | 235 | if (fd > 2) |
237 | close (fd); | 236 | close(fd); |
238 | } | 237 | } |
239 | 238 | ||
240 | s = getenv("TERM"); | 239 | s = getenv("TERM"); |
241 | if (ioctl(0, TIOCGSERIAL, &sr) == 0) { | 240 | if (ioctl(STDIN_FILENO, TIOCGSERIAL, &sr) == 0) { |
242 | /* Force the TERM setting to vt102 for serial console | 241 | /* Force the TERM setting to vt102 for serial console |
243 | * if TERM is set to linux (the default) */ | 242 | * if TERM is set to linux (the default) */ |
244 | if (!s || strcmp(s, "linux") == 0) | 243 | if (!s || strcmp(s, "linux") == 0) |