mirror of
https://github.com/troglobit/finit.git
synced 2026-11-08 16:11:10 +00:00
ttinit: check retun value from tcgetattr(), only restore if OK
Found by Coverity Scan. Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
1 parent
8d3917e9fa
commit
6d380082eb
1 file changed
+11
-6
+11
-6
@@ -370,16 +370,20 @@ int ttinit(void)
|
|||||||
struct pollfd fd = { STDIN_FILENO, POLLIN, 0 };
|
struct pollfd fd = { STDIN_FILENO, POLLIN, 0 };
|
||||||
struct winsize ws = { 0 };
|
struct winsize ws = { 0 };
|
||||||
struct termios tc, saved;
|
struct termios tc, saved;
|
||||||
|
int cached = 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Basic TTY init, CLOCaL is important or TIOCWINSZ will block
|
* Basic TTY init, CLOCaL is important or TIOCWINSZ will block
|
||||||
* until DCD is asserted, and we won't ever get it.
|
* until DCD is asserted, and we won't ever get it.
|
||||||
*/
|
*/
|
||||||
tcgetattr(STDERR_FILENO, &tc);
|
if (!tcgetattr(STDERR_FILENO, &tc)) {
|
||||||
saved = tc;
|
saved = tc;
|
||||||
tc.c_cflag |= (CLOCAL | CREAD);
|
cached = 1;
|
||||||
tc.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
|
|
||||||
tcsetattr(STDERR_FILENO, TCSANOW, &tc);
|
tc.c_cflag |= (CLOCAL | CREAD);
|
||||||
|
tc.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
|
||||||
|
tcsetattr(STDERR_FILENO, TCSANOW, &tc);
|
||||||
|
}
|
||||||
|
|
||||||
/* 1. Try TIOCWINSZ to query window size from kernel */
|
/* 1. Try TIOCWINSZ to query window size from kernel */
|
||||||
if (!ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws)) {
|
if (!ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws)) {
|
||||||
@@ -411,7 +415,8 @@ int ttinit(void)
|
|||||||
fprintf(stderr, "\e8");
|
fprintf(stderr, "\e8");
|
||||||
}
|
}
|
||||||
|
|
||||||
tcsetattr(STDERR_FILENO, TCSANOW, &saved);
|
if (cached)
|
||||||
|
tcsetattr(STDERR_FILENO, TCSANOW, &saved);
|
||||||
|
|
||||||
/* Sanity check */
|
/* Sanity check */
|
||||||
if (ttcols <= 0)
|
if (ttcols <= 0)
|
||||||
|
|||||||
Reference in new issue
Block a user