mirror of
https://github.com/troglobit/finit.git
synced 2026-11-02 13:20:32 +00:00
Fix #84: Reset TTY w/ stty() before taking any pre-getty action
This patch moves the stty() function from getty.c to a separate file so it can be called from exec.c as well. The fix to #84 is simply to call stty() in prepare_tty(), which is shared by run_getty() and run_getty2() and called before "Please press Enter ...". Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
1 parent
b45c3d5cb8
commit
250e26f2f6
5 files changed
+79
-39
No files matched your search
+1
-1
@@ -14,7 +14,7 @@ finit_SOURCES = api.c \
|
|||||||
client.c \
|
client.c \
|
||||||
conf.c conf.h \
|
conf.c conf.h \
|
||||||
exec.c finit.c finit.h \
|
exec.c finit.c finit.h \
|
||||||
getty.c \
|
getty.c stty.c \
|
||||||
helpers.c helpers.h \
|
helpers.c helpers.h \
|
||||||
log.c log.h \
|
log.c log.h \
|
||||||
mdadm.c mount.c pid.c \
|
mdadm.c mount.c pid.c \
|
||||||
|
|||||||
+7
-2
@@ -240,8 +240,13 @@ static void prepare_tty(char *tty, char *procname)
|
|||||||
struct termios term;
|
struct termios term;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Disable INTR, QUIT, SUSP, and DSUSP while handing over to
|
* Reset to sane defaults in case of messup from prev. session
|
||||||
* getty. It is up to the getty process to allow ISIG again.
|
*/
|
||||||
|
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);
|
tcdrain(STDIN_FILENO);
|
||||||
if (!tcgetattr(STDIN_FILENO, &term)) {
|
if (!tcgetattr(STDIN_FILENO, &term)) {
|
||||||
|
|||||||
-36
@@ -64,42 +64,6 @@ static int readch(char *tty)
|
|||||||
return ch1 & 0xFF;
|
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
|
* Parse and display a line from /etc/issue
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -48,6 +48,8 @@ struct fstab *getfsent (void);
|
|||||||
|
|
||||||
char *strip_line (char *line);
|
char *strip_line (char *line);
|
||||||
|
|
||||||
|
int stty (int fd, unsigned int speed);
|
||||||
|
|
||||||
int pid_alive (pid_t pid);
|
int pid_alive (pid_t pid);
|
||||||
char *pid_get_name (pid_t pid, char *name, size_t len);
|
char *pid_get_name (pid_t pid, char *name, size_t len);
|
||||||
|
|
||||||
|
|||||||
+69
@@ -0,0 +1,69 @@
|
|||||||
|
/* Reset terminal line settings (stty sane)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2016-2017 Joachim Nilsson <troglobit@gmail.com>
|
||||||
|
*
|
||||||
|
* 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 <unistd.h> /* _POSIX_VDISABLE */
|
||||||
|
#include <sys/ttydefaults.h> /* Not included by default in musl libc */
|
||||||
|
#include <termios.h>
|
||||||
|
|
||||||
|
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:
|
||||||
|
*/
|
||||||
Reference in new issue
Block a user