Mild refactoring of exec_block_or_func_process

Reduce some code duplication.
This commit is contained in:
ridiculousfish 2020-01-13 14:28:28 -08:00
parent 399062c219
commit 7b25787e52

View file

@ -781,23 +781,15 @@ static bool exec_block_or_func_process(parser_t &parser, const std::shared_ptr<j
} }
// If we have a block output buffer, populate it now. // If we have a block output buffer, populate it now.
if (!block_output_bufferfill) { std::string buffer_contents;
// No buffer, so we exit directly. This means we have to manually set the exit if (block_output_bufferfill) {
// status. // Remove our write pipe and forget it. This may close the pipe, unless another thread has
p->completed = true; // claimed it (background write) or another process has inherited it.
if (p->is_last_in_job) { io_chain.remove(block_output_bufferfill);
parser.set_last_statuses(j->get_statuses()); auto block_output_buffer = io_bufferfill_t::finish(std::move(block_output_bufferfill));
} buffer_contents = block_output_buffer->buffer().newline_serialized();
return true;
} }
assert(block_output_bufferfill && "Must have a block output bufferfiller");
// Remove our write pipe and forget it. This may close the pipe, unless another thread has
// claimed it (background write) or another process has inherited it.
io_chain.remove(block_output_bufferfill);
auto block_output_buffer = io_bufferfill_t::finish(std::move(block_output_bufferfill));
std::string buffer_contents = block_output_buffer->buffer().newline_serialized();
if (!buffer_contents.empty()) { if (!buffer_contents.empty()) {
return run_internal_process(p, std::move(buffer_contents), {} /*errdata*/, io_chain); return run_internal_process(p, std::move(buffer_contents), {} /*errdata*/, io_chain);
} else { } else {