aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-03-05 19:22:04 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-03-05 19:22:04 +0000
commitd238a477b7491ba4d2cd21f7fa32021e2f755698 (patch)
tree43df5b69a4a6e514c0100628c9d7d0f3e1fb3dd3
parentec77ba128ad8889593f5534dcfdd14645e07f4d3 (diff)
downloadbusybox-w32-d238a477b7491ba4d2cd21f7fa32021e2f755698.tar.gz
busybox-w32-d238a477b7491ba4d2cd21f7fa32021e2f755698.tar.bz2
busybox-w32-d238a477b7491ba4d2cd21f7fa32021e2f755698.zip
init: fix handling of stdio file descriptors
-rw-r--r--init/init.c20
1 files changed, 10 insertions, 10 deletions
diff --git a/init/init.c b/init/init.c
index e1ad1e615..698563228 100644
--- a/init/init.c
+++ b/init/init.c
@@ -201,7 +201,7 @@ static void message(int device, const char *fmt, ...)
201} 201}
202 202
203/* Set terminal settings to reasonable defaults */ 203/* Set terminal settings to reasonable defaults */
204static void set_term(void) 204static void set_sane_term(void)
205{ 205{
206 struct termios tty; 206 struct termios tty;
207 207
@@ -313,9 +313,8 @@ static void open_stdio_to_tty(const char* tty_name, int fail)
313{ 313{
314 /* empty tty_name means "use init's tty", else... */ 314 /* empty tty_name means "use init's tty", else... */
315 if (tty_name[0]) { 315 if (tty_name[0]) {
316 close(0); 316 int fd = device_open(tty_name, O_RDWR);
317 if ((device_open(tty_name, O_RDWR)) < 0) { 317 if (fd < 0) {
318 dup2(1, 0); /* restore fd #0 - avoid nasty surprises */
319 message(L_LOG | L_CONSOLE, "Can't open %s: %s", 318 message(L_LOG | L_CONSOLE, "Can't open %s: %s",
320 tty_name, strerror(errno)); 319 tty_name, strerror(errno));
321 if (fail) 320 if (fail)
@@ -325,13 +324,14 @@ static void open_stdio_to_tty(const char* tty_name, int fail)
325#else 324#else
326 _exit(2); 325 _exit(2);
327#endif 326#endif
327 } else {
328 dup2(fd, 0);
329 dup2(fd, 1);
330 dup2(fd, 2);
331 if (fd > 2) close(fd);
328 } 332 }
329 } 333 }
330 close(1); 334 set_sane_term();
331 close(2);
332 set_term();
333 dup(0);
334 dup(0);
335} 335}
336 336
337static pid_t run(const struct init_action *a) 337static pid_t run(const struct init_action *a)
@@ -926,7 +926,7 @@ int init_main(int argc, char **argv)
926 926
927 /* Figure out where the default console should be */ 927 /* Figure out where the default console should be */
928 console_init(); 928 console_init();
929 set_term(); 929 set_sane_term();
930 chdir("/"); 930 chdir("/");
931 setsid(); 931 setsid();
932 { 932 {