From 285c1f3a3eda762897d45f698e94c461d68e8d68 Mon Sep 17 00:00:00 2001 From: Sami Kerola Date: Sat, 14 May 2016 19:50:41 +0100 Subject: lib: try to find tty in get_terminal_name() Try all standard terminal input/output file descriptors when finding tty name in get_germinal_name(). This should make all invocations of the function as robust as they can get. Signed-off-by: Sami Kerola --- term-utils/write.c | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) (limited to 'term-utils/write.c') diff --git a/term-utils/write.c b/term-utils/write.c index be91218cf..6bd393441 100644 --- a/term-utils/write.c +++ b/term-utils/write.c @@ -296,7 +296,7 @@ static void do_write(const struct write_control *ctl) int main(int argc, char **argv) { - int tty_writeable = 0, src_fd, c; + int tty_writeable = 0, c; struct write_control ctl = { 0 }; static const struct option longopts[] = { @@ -321,18 +321,8 @@ int main(int argc, char **argv) usage(stderr); } - /* check that sender has write enabled */ - if (isatty(STDIN_FILENO)) - src_fd = STDIN_FILENO; - else if (isatty(STDOUT_FILENO)) - src_fd = STDOUT_FILENO; - else if (isatty(STDERR_FILENO)) - src_fd = STDERR_FILENO; - else - src_fd = -1; - - if (src_fd != -1 && - get_terminal_name(src_fd, &ctl.src_tty_path, &ctl.src_tty_name, NULL) == 0) { + if (get_terminal_name(&ctl.src_tty_path, &ctl.src_tty_name, NULL) == 0) { + /* check that sender has write enabled */ if (check_tty(ctl.src_tty_path, &tty_writeable, NULL, 1)) exit(EXIT_FAILURE); if (!tty_writeable) -- cgit v1.2.3-55-g7522