From: Todd C. Miller Date: Tue, 11 May 2010 12:12:02 +0000 (-0400) Subject: Also start the command in the background if stdin is not a tty. X-Git-Tag: SUDO_1_8_0~653 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=02f8c187a5fccf125fc11d3e7c455c92ac97ecb2;p=sudo Also start the command in the background if stdin is not a tty. --- diff --git a/src/script.c b/src/script.c index 3d8527cc2..e601c3358 100644 --- a/src/script.c +++ b/src/script.c @@ -107,7 +107,7 @@ struct io_buffer { }; static int script_fds[6] = { -1, -1, -1, -1, -1, -1}; -static int ttyin = TRUE; +static int pipeline = FALSE; static sig_atomic_t recvsig[NSIG]; static sig_atomic_t ttymode = TERM_COOKED; @@ -563,7 +563,7 @@ script_execve(struct command_details *details, char *argv[], char *envp[], */ memset(io_pipe, 0, sizeof(io_pipe)); if (!isatty(STDIN_FILENO)) { - ttyin = FALSE; + pipeline = TRUE; if (pipe(io_pipe[STDIN_FILENO]) != 0) error(1, "unable to create pipe"); iobufs = io_buf_new(STDIN_FILENO, io_pipe[STDIN_FILENO][1], @@ -571,6 +571,7 @@ script_execve(struct command_details *details, char *argv[], char *envp[], script_fds[SFD_STDIN] = io_pipe[STDIN_FILENO][0]; } if (!isatty(STDOUT_FILENO)) { + pipeline = TRUE; if (pipe(io_pipe[STDOUT_FILENO]) != 0) error(1, "unable to create pipe"); iobufs = io_buf_new(io_pipe[STDOUT_FILENO][0], STDOUT_FILENO, @@ -601,8 +602,8 @@ script_execve(struct command_details *details, char *argv[], char *envp[], sync_ttysize(script_fds[SFD_USERTTY], script_fds[SFD_SLAVE]); } - /* Start out in raw mode is stdin is a tty. */ - if (ttyin) { + /* Start out in raw mode if we are not part of a pipeline. */ + if (!pipeline) { ttymode = TERM_RAW; do { n = term_raw(script_fds[SFD_USERTTY], 0); @@ -971,12 +972,12 @@ script_child(const char *path, char *argv[], char *envp[], int backchannel, int #endif /* - * If stdin is not a tty, start command in the background since - * it might be part of a pipeline that reads from /dev/tty. + * If stdin/stdout is not a tty, start command in the background + * since it might be part of a pipeline that reads from /dev/tty. * In this case, we rely on the command receiving SIGTTOU or SIGTTIN * when it needs access to the controlling tty. */ - if (foreground && !ttyin) + if (pipeline) foreground = 0; /* Start command and wait for it to stop or exit */