diff --git a/src/Makefile.am b/src/Makefile.am index 79ede895..c3731994 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -14,7 +14,7 @@ finit_SOURCES = api.c \ client.c \ conf.c conf.h \ exec.c finit.c finit.h \ - getty.c \ + getty.c stty.c \ helpers.c helpers.h \ log.c log.h \ mdadm.c mount.c pid.c \ diff --git a/src/exec.c b/src/exec.c index bf2d8931..b776c281 100644 --- a/src/exec.c +++ b/src/exec.c @@ -240,8 +240,13 @@ static void prepare_tty(char *tty, char *procname) struct termios term; /* - * Disable INTR, QUIT, SUSP, and DSUSP while handing over to - * getty. It is up to the getty process to allow ISIG again. + * Reset to sane defaults in case of messup from prev. session + */ + stty(STDIN_FILENO, B38400); + + /* + * Disable ISIG (INTR, QUIT, SUSP) before handing over to getty. + * It is up to the getty process to allow them again. */ tcdrain(STDIN_FILENO); if (!tcgetattr(STDIN_FILENO, &term)) { diff --git a/src/getty.c b/src/getty.c index 43b8d7d5..c3ed7be4 100644 --- a/src/getty.c +++ b/src/getty.c @@ -64,42 +64,6 @@ static int readch(char *tty) return ch1 & 0xFF; } -static void stty(int fd, speed_t speed) -{ - struct termios term; - - tcdrain(fd); - if (tcgetattr(fd, &term)) - return; - - cfsetispeed(&term, speed); - cfsetospeed(&term, speed); - tcsetattr(fd, TCSAFLUSH, &term); - tcflush(fd, TCIOFLUSH); - - /* Disable modem specific flags */ - term.c_cflag &= ~(0|CSTOPB|PARENB|PARODD); - term.c_cflag &= ~CRTSCTS; - term.c_cflag |= CLOCAL; - - /* Timeouts, minimum chars and default flags */ - term.c_cc[VTIME] = 0; - term.c_cc[VMIN] = 1; - term.c_iflag = ICRNL|IXON|IXOFF; - term.c_oflag = OPOST|ONLCR; - term.c_cflag |= CS8|CREAD|HUPCL|CBAUDEX; - term.c_lflag |= ICANON|ISIG|ECHO|ECHOE|ECHOK|ECHOKE; - - /* Reset special characters to defaults */ - term.c_cc[VINTR] = CTRL('C'); - term.c_cc[VQUIT] = CTRL('\\'); - term.c_cc[VEOF] = CTRL('D'); - term.c_cc[VEOL] = '\n'; - term.c_cc[VKILL] = CTRL('U'); - term.c_cc[VERASE] = CERASE; - tcsetattr(fd, TCSANOW, &term); -} - /* * Parse and display a line from /etc/issue */ diff --git a/src/helpers.h b/src/helpers.h index dbc694c9..7a70af28 100644 --- a/src/helpers.h +++ b/src/helpers.h @@ -48,6 +48,8 @@ struct fstab *getfsent (void); char *strip_line (char *line); +int stty (int fd, unsigned int speed); + int pid_alive (pid_t pid); char *pid_get_name (pid_t pid, char *name, size_t len); diff --git a/src/stty.c b/src/stty.c new file mode 100644 index 00000000..00ec911f --- /dev/null +++ b/src/stty.c @@ -0,0 +1,69 @@ +/* Reset terminal line settings (stty sane) + * + * Copyright (c) 2016-2017 Joachim Nilsson + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include /* _POSIX_VDISABLE */ +#include /* Not included by default in musl libc */ +#include + +void stty(int fd, speed_t speed) +{ + struct termios term; + + tcdrain(fd); + if (tcgetattr(fd, &term)) + return; + + cfsetispeed(&term, speed); + cfsetospeed(&term, speed); + tcsetattr(fd, TCSAFLUSH, &term); + tcflush(fd, TCIOFLUSH); + + /* Disable modem specific flags */ + term.c_cflag &= ~(0|CSTOPB|PARENB|PARODD); + term.c_cflag &= ~CRTSCTS; + term.c_cflag |= CLOCAL; + + /* Timeouts, minimum chars and default flags */ + term.c_cc[VTIME] = 0; + term.c_cc[VMIN] = 1; + term.c_iflag = ICRNL|IXON|IXOFF; + term.c_oflag = OPOST|ONLCR; + term.c_cflag |= CS8|CREAD|HUPCL|CBAUDEX; + term.c_lflag |= ICANON|ISIG|ECHO|ECHOE|ECHOK|ECHOKE; + + /* Reset special characters to defaults */ + term.c_cc[VINTR] = CTRL('C'); + term.c_cc[VQUIT] = CTRL('\\'); + term.c_cc[VEOF] = CTRL('D'); + term.c_cc[VEOL] = '\n'; + term.c_cc[VKILL] = CTRL('U'); + term.c_cc[VERASE] = CERASE; + tcsetattr(fd, TCSANOW, &term); +} + +/** + * Local Variables: + * indent-tabs-mode: t + * c-file-style: "linux" + * End: + */