initscr(): Check if stdin and stdout are TTYs first

Programs that may be called in the background or with the stdin/stdout
redirected are not proper TTYs and we should not try to perform any
tricks on them.  This patch checks isatty() and returns standard term
sizes as a fallback.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson
2017-10-24 08:31:43 +02:00
parent 485463c70e
commit ef0db5e766
+7
View File
@@ -19,6 +19,7 @@
#define CONIO_H_
#include <stdio.h>
#include <unistd.h>
/* Attributes */
#define RESETATTR 0
@@ -94,6 +95,12 @@ static inline void initscr(int *row, int *col)
struct termios tc, saved;
struct pollfd fd = { STDIN_FILENO, POLLIN, 0 };
if (!isatty(STDIN_FILENO) || !isatty(STDOUT_FILENO)) {
*row = 24;
*col = 80;
return;
}
/* Disable echo to terminal while probing */
tcgetattr(STDERR_FILENO, &tc);
saved = tc;