From: Todd C. Miller Date: Wed, 23 May 2012 18:17:41 +0000 (-0400) Subject: Don't try to restore the terminal if we are not the foreground X-Git-Tag: SUDO_1_7_10~92 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=97bf893259bc7d85a2991ff96a01616620ee82a0;p=sudo Don't try to restore the terminal if we are not the foreground process. Otherwise, we may be stopped by SIGTTOU when we try to update the terminal settings when cleaning up. --HG-- branch : 1.7 --- diff --git a/exec_pty.c b/exec_pty.c index ef39f80e9..b0bc8f0bb 100644 --- a/exec_pty.c +++ b/exec_pty.c @@ -525,9 +525,12 @@ pty_close(cstat) flush_output(); if (io_fds[SFD_USERTTY] != -1) { - do { - n = term_restore(io_fds[SFD_USERTTY], 0); - } while (!n && errno == EINTR); + check_foreground(); + if (foreground) { + do { + n = term_restore(io_fds[SFD_USERTTY], 0); + } while (!n && errno == EINTR); + } } /* If child was signalled, write the reason to stdout like the shell. */ @@ -1080,3 +1083,14 @@ safe_close(fd) } return close(fd); } + +void +cleanup_pty(gotsignal) + int gotsignal; +{ + if (io_fds[SFD_USERTTY] != -1) { + check_foreground(); + if (foreground) + term_restore(io_fds[SFD_USERTTY], 0); + } +} diff --git a/sudo.c b/sudo.c index ad90d3926..584f4ff27 100644 --- a/sudo.c +++ b/sudo.c @@ -1331,7 +1331,9 @@ cleanup(gotsignal) io_log_close(); #endif } - term_restore(STDIN_FILENO, 0); +#ifdef _PATH_SUDO_IO_LOGDIR + cleanup_pty(gotsignal); +#endif #ifdef HAVE_SELINUX selinux_restore_tty(); #endif diff --git a/sudo.h b/sudo.h index b106162d4..32471f2e3 100644 --- a/sudo.h +++ b/sudo.h @@ -239,6 +239,9 @@ int sudo_execve __P((const char *path, char *argv[], char *envp[], uid_t uid, void save_signals __P((void)); void restore_signals __P((void)); +/* exec_pty.c */ +void cleanup_pty __P((int gotsignal)); + /* fileops.c */ char *sudo_parseln __P((FILE *)); int lock_file __P((int, int));