From 635365654d192ec7f5034eb87b5e27af39f83117 Mon Sep 17 00:00:00 2001 From: Kurtis Rader Date: Sun, 13 Aug 2017 15:29:50 -0700 Subject: [PATCH] Revert "Fixed cases where first command in chain would stay blocked" This reverts commit fb13b370e26b66fee6f662ac58e06ed04b47fbc9. It was meant for the major branch. --- src/exec.cpp | 37 ++++++++++++++----------------------- 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/src/exec.cpp b/src/exec.cpp index c5c60ab9c..35b007fed 100644 --- a/src/exec.cpp +++ b/src/exec.cpp @@ -493,7 +493,7 @@ void exec_job(parser_t &parser, job_t *j) { // // We are careful to set these to -1 when closed, so if we exit the loop abruptly, we can still // close them. - static pid_t blocked_pid = -1; + int last_pid = -1; int pipe_current_read = -1, pipe_current_write = -1, pipe_next_read = -1; for (std::unique_ptr &unique_p : j->processes) { if (exec_error) { @@ -511,7 +511,6 @@ void exec_job(parser_t &parser, job_t *j) { // See if we need a pipe. const bool pipes_to_next_command = !p->is_last_in_job; - bool command_blocked = false; //these semaphores will be used to make sure the first process lives long enough for the //next process in the chain to open its handles, process group, etc. @@ -1068,27 +1067,20 @@ void exec_job(parser_t &parser, job_t *j) { if (pid == 0) { // This is the child process. p->pid = getpid(); - // the process will be resumed by the shell when the next command in the - // chain is started - setup_child_process(j, p, process_net_io_chain); - // start child processes that are part of a job in a stopped state // to ensure that they are still running when the next command in the // chain is started. if (pipes_to_next_command) { + debug(3, L"Blocking process %d waiting for next command in chain.\n", p->pid); kill(p->pid, SIGSTOP); } - + // the process will be resumed by the shell when the next command in the + // chain is started + setup_child_process(j, p, process_net_io_chain); safe_launch_process(p, actual_cmd, argv, envv); // safe_launch_process _never_ returns... DIE("safe_launch_process should not have returned"); } else { - if (pipes_to_next_command) { - //it actually blocked itself after forking above, but print in here for output - //synchronization and so we can assign blocked_pid in the correct address space - debug(2, L"Blocking process %d waiting for next command in chain.\n", pid); - command_blocked = true; - } debug(2, L"Fork #%d, pid %d: external command '%s' from '%ls'", g_fork_count, pid, p->argv0(), file ? file : L""); if (pid < 0) { @@ -1112,16 +1104,6 @@ void exec_job(parser_t &parser, job_t *j) { } } - if (blocked_pid != -1) { - //now that next command in the chain has been started, unblock the previous command - debug(2, L"Unblocking process %d.\n", blocked_pid); - kill(blocked_pid, SIGCONT); - blocked_pid = -1; - } - if (command_blocked) { - blocked_pid = p->pid; - } - // Close the pipe the current process uses to read from the previous process_t. if (pipe_current_read >= 0) { exec_close(pipe_current_read); @@ -1133,6 +1115,15 @@ void exec_job(parser_t &parser, job_t *j) { exec_close(pipe_current_write); pipe_current_write = -1; } + + //now that next command in the chain has been started, unblock the previous command + if (last_pid != -1) { + debug(3, L"Unblocking process %d.\n", last_pid); + kill(last_pid, SIGCONT); + } + if (pid != 0) { + last_pid = pid; + } } // Clean up any file descriptors we left open.