From cc7618985a490b7521af231b50d292327fd324cc Mon Sep 17 00:00:00 2001 From: Norio Nomura Date: Tue, 7 Jan 2020 21:48:57 +0900 Subject: [PATCH] Don't override exit status when stderr is closed by `2>&-` fixes #6470 --- src/exec.cpp | 2 +- tests/checks/exit-status-with-closing-stderr.fish | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 tests/checks/exit-status-with-closing-stderr.fish diff --git a/src/exec.cpp b/src/exec.cpp index 00d47bde6..ba4910565 100644 --- a/src/exec.cpp +++ b/src/exec.cpp @@ -292,7 +292,7 @@ static bool run_internal_process(process_t *p, std::string outdata, std::string // If we have nothing to write we can elide the thread. // TODO: support eliding output to /dev/null. if (f->skip_out() && f->skip_err()) { - f->internal_proc->mark_exited(proc_status_t::from_exit_code(EXIT_SUCCESS)); + f->internal_proc->mark_exited(p->status); return true; } diff --git a/tests/checks/exit-status-with-closing-stderr.fish b/tests/checks/exit-status-with-closing-stderr.fish new file mode 100644 index 000000000..149a59f42 --- /dev/null +++ b/tests/checks/exit-status-with-closing-stderr.fish @@ -0,0 +1,5 @@ +# RUN: %fish %s +argparse r-require= -- --require 2>/dev/null ; echo $status +# CHECK: 2 +argparse r-require= -- --require 2>&- ; echo $status +# CHECK: 2