mirror of
https://github.com/sheumann/hush.git
synced 2025-03-11 18:30:22 +00:00
init: fix handling of stdio file descriptors
This commit is contained in:
parent
ec77ba128a
commit
d238a477b7
20
init/init.c
20
init/init.c
@ -201,7 +201,7 @@ static void message(int device, const char *fmt, ...)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Set terminal settings to reasonable defaults */
|
/* Set terminal settings to reasonable defaults */
|
||||||
static void set_term(void)
|
static void set_sane_term(void)
|
||||||
{
|
{
|
||||||
struct termios tty;
|
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... */
|
/* empty tty_name means "use init's tty", else... */
|
||||||
if (tty_name[0]) {
|
if (tty_name[0]) {
|
||||||
close(0);
|
int fd = device_open(tty_name, O_RDWR);
|
||||||
if ((device_open(tty_name, O_RDWR)) < 0) {
|
if (fd < 0) {
|
||||||
dup2(1, 0); /* restore fd #0 - avoid nasty surprises */
|
|
||||||
message(L_LOG | L_CONSOLE, "Can't open %s: %s",
|
message(L_LOG | L_CONSOLE, "Can't open %s: %s",
|
||||||
tty_name, strerror(errno));
|
tty_name, strerror(errno));
|
||||||
if (fail)
|
if (fail)
|
||||||
@ -325,13 +324,14 @@ static void open_stdio_to_tty(const char* tty_name, int fail)
|
|||||||
#else
|
#else
|
||||||
_exit(2);
|
_exit(2);
|
||||||
#endif
|
#endif
|
||||||
|
} else {
|
||||||
|
dup2(fd, 0);
|
||||||
|
dup2(fd, 1);
|
||||||
|
dup2(fd, 2);
|
||||||
|
if (fd > 2) close(fd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
close(1);
|
set_sane_term();
|
||||||
close(2);
|
|
||||||
set_term();
|
|
||||||
dup(0);
|
|
||||||
dup(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static pid_t run(const struct init_action *a)
|
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 */
|
/* Figure out where the default console should be */
|
||||||
console_init();
|
console_init();
|
||||||
set_term();
|
set_sane_term();
|
||||||
chdir("/");
|
chdir("/");
|
||||||
setsid();
|
setsid();
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user