From: Todd C. Miller Date: Fri, 1 Dec 2017 20:43:06 +0000 (-0700) Subject: When the command completes, make the monitor the foreground process X-Git-Tag: SUDO_1_8_22^2~57 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b561d0d7ddf7e16472abd03fdada1ef2381f55cc;p=sudo When the command completes, make the monitor the foreground process group before informing the main sudo process of the command's exit status. This will prevent processes started by the command (which runs in a different process group) from receiving SIGHUP since the kernel sends SIGHUP to the foreground process group associated with the terminal session. The monitor has a SIGHUP handler installed so the signal is effectively ignored. --- diff --git a/src/exec_monitor.c b/src/exec_monitor.c index 470f7a069..d497f620c 100644 --- a/src/exec_monitor.c +++ b/src/exec_monitor.c @@ -630,6 +630,17 @@ exec_monitor(struct command_details *details, sigset_t *oset, } while (pid == -1 && errno == EINTR); /* XXX - update cstat with wait status? */ } + + /* + * Take the controlling tty. This prevents processes spawned by the + * command from receiving SIGHUP when the session leader (us) exits. + */ + if (tcsetpgrp(io_fds[SFD_SLAVE], mc.mon_pgrp) == -1) { + sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_ERRNO, + "%s: unable to set foreground pgrp to %d (monitor)", + __func__, (int)mc.mon_pgrp); + } + /* Send parent status. */ send_status(backchannel, &cstat);