summaryrefslogtreecommitdiff
path: root/init/init.c
diff options
context:
space:
mode:
authorDenis Vlasenko2007-03-05 19:22:04 +0000
committerDenis Vlasenko2007-03-05 19:22:04 +0000
commitd238a477b7491ba4d2cd21f7fa32021e2f755698 (patch)
tree43df5b69a4a6e514c0100628c9d7d0f3e1fb3dd3 /init/init.c
parentec77ba128ad8889593f5534dcfdd14645e07f4d3 (diff)
downloadbusybox-d238a477b7491ba4d2cd21f7fa32021e2f755698.zip
busybox-d238a477b7491ba4d2cd21f7fa32021e2f755698.tar.gz
init: fix handling of stdio file descriptors
Diffstat (limited to 'init/init.c')
-rw-r--r--init/init.c20
1 files changed, 10 insertions, 10 deletions
diff --git a/init/init.c b/init/init.c
index e1ad1e6..6985632 100644
--- a/init/init.c
+++ b/init/init.c
@@ -201,7 +201,7 @@ static void message(int device, const char *fmt, ...)
}
/* Set terminal settings to reasonable defaults */
-static void set_term(void)
+static void set_sane_term(void)
{
struct termios tty;
@@ -313,9 +313,8 @@ static void open_stdio_to_tty(const char* tty_name, int fail)
{
/* empty tty_name means "use init's tty", else... */
if (tty_name[0]) {
- close(0);
- if ((device_open(tty_name, O_RDWR)) < 0) {
- dup2(1, 0); /* restore fd #0 - avoid nasty surprises */
+ int fd = device_open(tty_name, O_RDWR);
+ if (fd < 0) {
message(L_LOG | L_CONSOLE, "Can't open %s: %s",
tty_name, strerror(errno));
if (fail)
@@ -325,13 +324,14 @@ static void open_stdio_to_tty(const char* tty_name, int fail)
#else
_exit(2);
#endif
+ } else {
+ dup2(fd, 0);
+ dup2(fd, 1);
+ dup2(fd, 2);
+ if (fd > 2) close(fd);
}
}
- close(1);
- close(2);
- set_term();
- dup(0);
- dup(0);
+ set_sane_term();
}
static pid_t run(const struct init_action *a)
@@ -926,7 +926,7 @@ int init_main(int argc, char **argv)
/* Figure out where the default console should be */
console_init();
- set_term();
+ set_sane_term();
chdir("/");
setsid();
{