Fix issue with VINTR, VEOF et al not being restored after boot

On Alpine Linux 3.6 the tcsetattr() calls failed.  This turned out to be
a deeply rooted issue not limited to just musl libc.  The workaround is
to call tcsetattr() in several rounds.  In particular the modem signals,
c_cflag bits, always fail, so we take a bet on Linux having set up the
terminals (hope as a strategy) and ignore that problem, for now.

Also, use TCSAFLUSH with tcsetattr(), that seems to work better and is
what BusyBox stty use.

The local CTL() macro is replaced with CTL() from ttydefaults.h, which
exists also in musl libc.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson
2020-04-26 22:06:59 +02:00
parent 83078d1947
commit 484aa0ba97
3 changed files with 19 additions and 20 deletions
+3 -3
View File
@@ -256,7 +256,7 @@ static void prepare_tty(char *tty, speed_t speed, char *procname, struct rlimit
term.c_lflag &= ~ISIG;
term.c_cc[VEOF] = _POSIX_VDISABLE;
term.c_cc[VINTR] = _POSIX_VDISABLE;
tcsetattr(STDIN_FILENO, TCSANOW, &term);
tcsetattr(STDIN_FILENO, TCSAFLUSH, &term);
}
/* Reset signal handlers that were set by the parent process */
@@ -309,7 +309,7 @@ static int activate_console(int noclear, int nowait)
c.c_oflag &= ~(OPOST);
c.c_cflag |= (CS8);
c.c_lflag &= ~(ECHO|ICANON|IEXTEN|ISIG);
tcsetattr(STDIN_FILENO, TCSANOW, &c);
tcsetattr(STDIN_FILENO, TCSAFLUSH, &c);
}
while (!fexist(SYNC_SHUTDOWN)) {
@@ -338,7 +338,7 @@ static int activate_console(int noclear, int nowait)
}
/* Restore TTY */
if (tcsetattr(STDIN_FILENO, TCSANOW, &orig) == -1)
if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &orig) == -1)
ret = 0;
return ret;