In term_restore(), only restores the terminal if we are in the

foregroup process group.  Instead of calling tcgetpgrp(), which is
racy, we set a temporary handler for SIGTTOU and check whether it
was received after a failed call to tcsetattr().
This commit is contained in:
Todd C. Miller
2014-02-05 12:03:58 -07:00
parent 85598f77b2
commit 135c85e152
2 changed files with 64 additions and 21 deletions

View File

@@ -115,11 +115,8 @@ pty_cleanup(void)
{
debug_decl(cleanup, SUDO_DEBUG_EXEC);
if (!TAILQ_EMPTY(&io_plugins) && io_fds[SFD_USERTTY] != -1) {
check_foreground();
if (foreground)
term_restore(io_fds[SFD_USERTTY], 0);
}
if (!TAILQ_EMPTY(&io_plugins) && io_fds[SFD_USERTTY] != -1)
term_restore(io_fds[SFD_USERTTY], 0);
#ifdef HAVE_SELINUX
selinux_restore_tty();
#endif
@@ -812,11 +809,8 @@ pty_close(struct command_status *cstat)
}
/* Restore terminal settings. */
if (io_fds[SFD_USERTTY] != -1) {
check_foreground();
if (foreground)
term_restore(io_fds[SFD_USERTTY], 0);
}
if (io_fds[SFD_USERTTY] != -1)
term_restore(io_fds[SFD_USERTTY], 0);
/* If child was signalled, write the reason to stdout like the shell. */
if (cstat->type == CMD_WSTATUS && WIFSIGNALED(cstat->val)) {