From 03695f4b5819d5f20ad0ad241d9255ba8cbd8e91 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Thu, 20 Jul 2023 10:46:14 +0100 Subject: 51977: PIPEFAIL interaction with ERREXIT / ERRRETURN Ensure the list-level error handling code is executed if we detect pipe failure for a foreground job. Add tests. --- ChangeLog | 6 ++++++ Src/jobs.c | 16 ++++++++++----- Test/E01options.ztst | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7d24a22dd..8ecc30f20 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2023-07-20 Peter Stephenson + + * 51977: Src/jobs.c, Test/E01options.ztst: Combination of + PIPEFAIL and ERRRETURN / ERREXIT options failed with complex + commands at end of pipeline. + 2023-07-19 dana * github #99: mirsella: Completion/Darwin/Command/_trash, diff --git a/Src/jobs.c b/Src/jobs.c index dd7bba405..a3b9f667a 100644 --- a/Src/jobs.c +++ b/Src/jobs.c @@ -427,11 +427,17 @@ storepipestats(Job jn, int inforeground, int fixlastval) } if (fixlastval) { - if (jn->stat & STAT_CURSH) { - if (!lastval && isset(PIPEFAIL)) - lastval = pipefail; - } else if (isset(PIPEFAIL)) - lastval = pipefail; + if (jn->stat & STAT_CURSH) { + if (!lastval && isset(PIPEFAIL)) { + if (inforeground) + this_noerrexit = 0; + lastval = pipefail; + } + } else if (isset(PIPEFAIL)) { + if (inforeground) + this_noerrexit = 0; + lastval = pipefail; + } } } diff --git a/Test/E01options.ztst b/Test/E01options.ztst index 533e08773..83f0371a1 100644 --- a/Test/E01options.ztst +++ b/Test/E01options.ztst @@ -1379,6 +1379,64 @@ F:Regression test for workers/41811 >1 >2 + pipefailfn1() { + emulate -L zsh + setopt errreturn pipefail + false | { true; } + print "Shouldn't get here, status $?" + } + pipefailfn1 +1:PIPE_FAIL causes ERR_RETURN with complex end of pipeline: braces + + pipefailfn2() { + emulate -L zsh + setopt errreturn pipefail + false | if true; then true; fi + print "Shouldn't get here, status $?" + } + pipefailfn2 || print Function failed, as expected +0:PIPE_FAIL causes ERR_RETURN with complex end of pipeline: if +>Function failed, as expected + + pipefailfn3() { + emulate -L zsh + setopt errreturn pipefail + false | while true; do break; done + print "Shouldn't get here, status $?" + } + pipefailfn3 || print Function failed, as expected +0:PIPE_FAIL causes ERR_RETURN with complex end of pipeline: while +>Function failed, as expected + + pipefailfn4() { + emulate -L zsh + setopt errreturn pipefail + false | true + print "Shouldn't get here, status $?" + } + pipefailfn4 +1:PIPE_FAIL causes ERR_RETURN in simple case + + pipefailfn5() { + emulate -L zsh + setopt errreturn pipefail + false | { true | true; } + print "Shouldn't get here, status $?" + } + pipefailfn5 || print Function failed as expected +0:PIPE_FAIL causes ERR_RETURN with nested successful pipe +>Function failed as expected + + pipefailfn6() { + emulate -L zsh + setopt errreturn pipefail + false | { false | true; } + print "Shouldn't get here, status $?" + } + pipefailfn6 || print Function failed as expected +0:PIPE_FAIL causes ERR_RETURN with nested failed pipe +>Function failed as expected + for (( i = 0; i < 10; i++ )); do () { print $i -- cgit 1.4.1