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.
This commit is contained in:
@@ -113,8 +113,11 @@ cleanup(int gotsignal)
|
|||||||
{
|
{
|
||||||
debug_decl(cleanup, SUDO_DEBUG_EXEC);
|
debug_decl(cleanup, SUDO_DEBUG_EXEC);
|
||||||
|
|
||||||
if (!tq_empty(&io_plugins))
|
if (!tq_empty(&io_plugins) && io_fds[SFD_USERTTY] != -1) {
|
||||||
term_restore(io_fds[SFD_USERTTY], 0);
|
check_foreground();
|
||||||
|
if (foreground) {
|
||||||
|
term_restore(io_fds[SFD_USERTTY], 0);
|
||||||
|
}
|
||||||
#ifdef HAVE_SELINUX
|
#ifdef HAVE_SELINUX
|
||||||
selinux_restore_tty();
|
selinux_restore_tty();
|
||||||
#endif
|
#endif
|
||||||
@@ -680,9 +683,12 @@ pty_close(struct command_status *cstat)
|
|||||||
flush_output();
|
flush_output();
|
||||||
|
|
||||||
if (io_fds[SFD_USERTTY] != -1) {
|
if (io_fds[SFD_USERTTY] != -1) {
|
||||||
do {
|
check_foreground();
|
||||||
n = term_restore(io_fds[SFD_USERTTY], 0);
|
if (foreground) {
|
||||||
} while (!n && errno == EINTR);
|
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. */
|
/* If child was signalled, write the reason to stdout like the shell. */
|
||||||
@@ -1004,7 +1010,7 @@ exec_monitor(struct command_details *details, int backchannel)
|
|||||||
goto done;
|
goto done;
|
||||||
if (errno == EINTR)
|
if (errno == EINTR)
|
||||||
continue;
|
continue;
|
||||||
error(1, _("select failed"));
|
error(1, "monitor: %s", _("select failed"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (FD_ISSET(signal_pipe[0], fdsr)) {
|
if (FD_ISSET(signal_pipe[0], fdsr)) {
|
||||||
@@ -1256,7 +1262,7 @@ safe_close(int fd)
|
|||||||
/* Avoid closing /dev/tty or std{in,out,err}. */
|
/* Avoid closing /dev/tty or std{in,out,err}. */
|
||||||
if (fd < 3 || fd == io_fds[SFD_USERTTY]) {
|
if (fd < 3 || fd == io_fds[SFD_USERTTY]) {
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
return -1;
|
debug_return_int(-1);
|
||||||
}
|
}
|
||||||
debug_return_int(close(fd));
|
debug_return_int(close(fd));
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user