From eb0fe83f5326e3801085491ab47fa80c3b49b393 Mon Sep 17 00:00:00 2001 From: Jan Engelhardt Date: Wed, 20 Mar 2013 22:56:12 +0100 Subject: [PATCH] xmp: avoid bogus warning message when stdin is /dev/null When xmp is run with /dev/null as stdin, the ctty operations on it will fail. Do not call these routines if it is not a tty. --- src/terminal.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/terminal.c b/src/terminal.c index 215d958..02eec2d 100644 --- a/src/terminal.c +++ b/src/terminal.c @@ -12,6 +12,7 @@ #ifdef HAVE_TERMIOS_H #include +#include static struct termios term; #endif @@ -21,14 +22,16 @@ int set_tty() #ifdef HAVE_TERMIOS_H struct termios t; - if (tcgetattr(0, &term) < 0) + if (!isatty(STDIN_FILENO)) + return 0; + if (tcgetattr(STDIN_FILENO, &term) < 0) return -1; t = term; t.c_lflag &= ~(ECHO | ICANON | TOSTOP); t.c_cc[VMIN] = t.c_cc[VTIME] = 0; - if (tcsetattr(0, TCSAFLUSH, &t) < 0) + if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &t) < 0) return -1; #endif @@ -38,7 +41,9 @@ int set_tty() int reset_tty() { #ifdef HAVE_TERMIOS_H - if (tcsetattr(0, TCSAFLUSH, &term) < 0) { + if (!isatty(STDIN_FILENO)) + return 0; + if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &term) < 0) { fprintf(stderr, "can't reset terminal!\n"); return -1; }