Set proper RAW mode for "Please press Enter to activate ..."

Also, while leading with a \n for the activation text and clearing the
line before getty is called, some getty implementations, e.g. BusyBox,
write an extra \n before printing /etc/issue.  For perfectionists that
want a single newline separating started services and the first line
of /etc/issue we now not only clear the line, we also move the cursor
one line up before handing over to getty.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson committed 2020-01-06 18:58:08 +01:00
1 parent 58ade5d74e
commit d1718d338e
1 file changed
+15 -12
+15 -12
View File
@@ -291,8 +291,8 @@ static void prepare_tty(char *tty, speed_t speed, char *procname, struct rlimit
static int activate_console(int noclear, int nowait) static int activate_console(int noclear, int nowait)
{ {
struct termios orig;
int ret = 0; int ret = 0;
struct termios term;
if (!noclear) if (!noclear)
(void)write(STDERR_FILENO, "\e[r\e[H\e[J", 9); (void)write(STDERR_FILENO, "\e[r\e[H\e[J", 9);
@@ -301,15 +301,20 @@ static int activate_console(int noclear, int nowait)
return 1; return 1;
/* Disable ECHO, XON/OFF while waiting for <CR> */ /* Disable ECHO, XON/OFF while waiting for <CR> */
if (!tcgetattr(STDIN_FILENO, &term)) { if (!tcgetattr(STDIN_FILENO, &orig)) {
term.c_iflag &= ~(IXON|IXOFF); struct termios c = orig;
term.c_lflag &= ~ECHO;
tcsetattr(STDIN_FILENO, TCSANOW, &term); c.c_iflag &= ~(BRKINT|ICRNL|INPCK|ISTRIP|IXON|IXOFF);
c.c_oflag &= ~(OPOST);
c.c_cflag |= (CS8);
c.c_lflag &= ~(ECHO|ICANON|IEXTEN|ISIG);
tcsetattr(STDIN_FILENO, TCSANOW, &c);
} }
while (!fexist(SYNC_SHUTDOWN)) { while (!fexist(SYNC_SHUTDOWN)) {
char c; char c;
static const char clr[] = "\r\e[2K"; static const char clr[] = "\r\e[2K";
static const char cup[] = "\e[A";
static const char msg[] = "\nPlease press Enter to activate this console."; static const char msg[] = "\nPlease press Enter to activate this console.";
if (fexist(SYNC_STOPPED)) { if (fexist(SYNC_STOPPED)) {
@@ -319,23 +324,21 @@ static int activate_console(int noclear, int nowait)
(void)write(STDERR_FILENO, clr, strlen(clr)); (void)write(STDERR_FILENO, clr, strlen(clr));
(void)write(STDERR_FILENO, msg, strlen(msg)); (void)write(STDERR_FILENO, msg, strlen(msg));
while (read(STDIN_FILENO, &c, 1) == 1 && c != '\n') while (read(STDIN_FILENO, &c, 1) == 1 && c != '\r')
continue; continue;
if (fexist(SYNC_STOPPED)) if (fexist(SYNC_STOPPED))
continue; continue;
(void)write(STDERR_FILENO, clr, strlen(clr)); (void)write(STDERR_FILENO, clr, strlen(clr));
(void)write(STDERR_FILENO, cup, strlen(cup));
ret = 1; ret = 1;
break; break;
} }
/* Restore ECHO, XON/OFF */ /* Restore TTY */
if (!tcgetattr(STDIN_FILENO, &term)) { if (tcsetattr(STDIN_FILENO, TCSANOW, &orig) == -1)
term.c_iflag |= IXON|IXOFF; ret = 0;
term.c_lflag |= ECHO;
tcsetattr(STDIN_FILENO, TCSANOW, &term);
}
return ret; return ret;
} }