From 284207b12dbfd13c25416cba69a151f54dabb6dc Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Wed, 13 Sep 2017 18:34:44 +0200 Subject: Only restore terminal settings if stdin still belongs to us (closes #324) --- src/main.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main.c b/src/main.c index cb2964f..bb4dec4 100644 --- a/src/main.c +++ b/src/main.c @@ -234,7 +234,15 @@ void feh_clean_exit(void) if(disp) XCloseDisplay(disp); - if (control_via_stdin && isatty(STDIN_FILENO)) + /* + * Only restore the old terminal settings if + * - we changed them in the first place + * - stdin still is a terminal (it might have been closed) + * - stdin still belongs to us (we might have been detached from the + * controlling terminal, in that case we probably shouldn't be messing + * around with it) + */ + if (control_via_stdin && isatty(STDIN_FILENO) && getpgrp() == (tcgetpgrp(STDIN_FILENO))) if (tcsetattr(STDIN_FILENO, TCSANOW, &old_term_settings) == -1) eprintf("tcsetattr failed"); -- cgit v1.2.3