From: Todd C. Miller Date: Wed, 29 Nov 2017 19:06:12 +0000 (-0700) Subject: We don't need to be the foreground process to be able to write to X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5ccc7ab8793571f0a93351d04883bb50512889e3;p=sudo We don't need to be the foreground process to be able to write to the terminal in most cases. If the background process tries to modify the terminal flags it will receive SIGTTOU which is relayed to the sudo front-end. This currently mishandles terminals with the TOSTOP local flag set. --- diff --git a/src/exec_pty.c b/src/exec_pty.c index f55506655..65caf2f6a 100644 --- a/src/exec_pty.c +++ b/src/exec_pty.c @@ -563,9 +563,8 @@ read_callback(int fd, int what, void *v) iob->ec->cmnd_pid = -1; } iob->len += n; - /* Enable writer if not /dev/tty or we are foreground pgrp. */ - if (iob->wevent != NULL && - (foreground || !USERTTY_EVENT(iob->wevent))) { + /* Enable writer now that there is data in the buffer. */ + if (iob->wevent != NULL) { if (sudo_ev_add(evbase, iob->wevent, NULL, false) == -1) sudo_fatal(U_("unable to add event to queue")); } @@ -1452,7 +1451,7 @@ add_io_events(struct sudo_event_base *evbase) * Normally, write buffers are added on demand when data is read. */ SLIST_FOREACH(iob, &iobufs, entries) { - /* Don't read/write from /dev/tty if we are not in the foreground. */ + /* Don't read from /dev/tty if we are not in the foreground. */ if (iob->revent != NULL && (ttymode == TERM_RAW || !USERTTY_EVENT(iob->revent))) { if (iob->len != sizeof(iob->buf)) { @@ -1463,8 +1462,8 @@ add_io_events(struct sudo_event_base *evbase) sudo_fatal(U_("unable to add event to queue")); } } - if (iob->wevent != NULL && - (foreground || !USERTTY_EVENT(iob->wevent))) { + if (iob->wevent != NULL) { + /* Enable writer if buffer is not empty. */ if (iob->len > iob->off) { sudo_debug_printf(SUDO_DEBUG_INFO, "added I/O wevent %p, fd %d, events %d",