From 607779257cd20b9556386e50895fa02290a255f0 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Tue, 28 Apr 2020 09:43:34 -0700 Subject: [PATCH] Introduce out_is_piped and err_is_piped on io_streams_t builtin_eval needs to know whether to set up bufferfills to capture its output and/or errput; it should do this specifically if the output and errput is piped (and not, say, directed to a file). In preparation for this change, add bools to io_streams_t which track whether stdout and stderr are specifically piped. --- src/exec.cpp | 11 +++++++++-- src/io.h | 7 ++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/exec.cpp b/src/exec.cpp index 6b473f0eb..e9f1818ad 100644 --- a/src/exec.cpp +++ b/src/exec.cpp @@ -416,9 +416,16 @@ static bool exec_internal_builtin_proc(parser_t &parser, process_t *p, const io_ } } + // Pull out the IOs for stdout and stderr. + auto out_io = proc_io_chain.io_for_fd(STDOUT_FILENO); + auto err_io = proc_io_chain.io_for_fd(STDERR_FILENO); + + // Set up our streams. streams.stdin_fd = local_builtin_stdin; - streams.out_is_redirected = proc_io_chain.io_for_fd(STDOUT_FILENO) != nullptr; - streams.err_is_redirected = proc_io_chain.io_for_fd(STDERR_FILENO) != nullptr; + streams.out_is_redirected = out_io != nullptr; + streams.err_is_redirected = err_io != nullptr; + streams.out_is_piped = (out_io != nullptr && out_io->io_mode == io_mode_t::pipe); + streams.err_is_piped = (err_io != nullptr && err_io->io_mode == io_mode_t::pipe); streams.stdin_is_directly_redirected = stdin_is_directly_redirected; streams.io_chain = &proc_io_chain; diff --git a/src/io.h b/src/io.h index d0f3d8e16..ce7edea8a 100644 --- a/src/io.h +++ b/src/io.h @@ -448,7 +448,12 @@ struct io_streams_t { // < foo.txt bool stdin_is_directly_redirected{false}; - // Indicates whether stdout and stderr are redirected (e.g. to a file or piped). + // Indicates whether stdout and stderr are specifically piped. + // If this is set, then the is_redirected flags must also be set. + bool out_is_piped{false}; + bool err_is_piped{false}; + + // Indicates whether stdout and stderr are at all redirected (e.g. to a file or piped). bool out_is_redirected{false}; bool err_is_redirected{false};