From 82ee3d6a4e174c065c2c0dba0037ce30646e365f Mon Sep 17 00:00:00 2001 From: Kurtis Rader Date: Sun, 13 Aug 2017 15:24:08 -0700 Subject: [PATCH] Revert "Deduplication between INTERNAL_FUNCTION and INTERNAL_BLOCK_NODE" This reverts commit 0594735714faf03e92863ebda67945a45521493e. It was meant for the major branch. --- src/exec.cpp | 52 +++++++++++++++++++++++++++------------------------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/src/exec.cpp b/src/exec.cpp index 891159005..72e615c30 100644 --- a/src/exec.cpp +++ b/src/exec.cpp @@ -685,28 +685,6 @@ void exec_job(parser_t &parser, job_t *j) { return true; }; - - //helper routine executed by INTERNAL_FUNCTION and INTERNAL_BLOCK_NODE to make sure - //an output buffer exists in case there is another command in the job chain that will - //be reading from this command's output. - auto verify_buffer_output = [&] () { - if (!p->is_last_in_job) { - // Be careful to handle failure, e.g. too many open fds. - block_output_io_buffer = io_buffer_t::create(STDOUT_FILENO, all_ios); - if (block_output_io_buffer.get() == NULL) { - exec_error = true; - job_mark_process_as_failed(j, p); - } else { - // This looks sketchy, because we're adding this io buffer locally - they - // aren't in the process or job redirection list. Therefore select_try won't - // be able to read them. However we call block_output_io_buffer->read() - // below, which reads until EOF. So there's no need to select on this. - process_net_io_chain.push_back(block_output_io_buffer); - } - } - }; - - switch (p->type) { case INTERNAL_FUNCTION: { // Calls to function_get_definition might need to source a file as a part of @@ -737,7 +715,20 @@ void exec_job(parser_t &parser, job_t *j) { parser.forbid_function(func_name); - verify_buffer_output(); + if (!p->is_last_in_job) { + // Be careful to handle failure, e.g. too many open fds. + block_output_io_buffer = io_buffer_t::create(STDOUT_FILENO, all_ios); + if (block_output_io_buffer.get() == NULL) { + exec_error = true; + job_mark_process_as_failed(j, p); + } else { + // This looks sketchy, because we're adding this io buffer locally - they + // aren't in the process or job redirection list. Therefore select_try won't + // be able to read them. However we call block_output_io_buffer->read() + // below, which reads until EOF. So there's no need to select on this. + process_net_io_chain.push_back(block_output_io_buffer); + } + } if (!exec_error) { internal_exec_helper(parser, def, NODE_OFFSET_INVALID, TOP, @@ -751,7 +742,18 @@ void exec_job(parser_t &parser, job_t *j) { } case INTERNAL_BLOCK_NODE: { - verify_buffer_output(); + if (!p->is_last_in_job) { + block_output_io_buffer = io_buffer_t::create(STDOUT_FILENO, all_ios); + if (block_output_io_buffer.get() == NULL) { + // We failed (e.g. no more fds could be created). + exec_error = true; + job_mark_process_as_failed(j, p); + } else { + // See the comment above about it's OK to add an IO redirection to this + // local buffer, even though it won't be handled in select_try. + process_net_io_chain.push_back(block_output_io_buffer); + } + } if (!exec_error) { internal_exec_helper(parser, wcstring(), p->internal_block_node, TOP, @@ -860,7 +862,7 @@ void exec_job(parser_t &parser, job_t *j) { const int fg = j->get_flag(JOB_FOREGROUND); j->set_flag(JOB_FOREGROUND, false); - //main loop may need to perform a blocking read from previous command's output. + //main loop is performing a blocking read from previous command's output //make sure read source is not blocked unblock_previous();