From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 449 invoked by alias); 5 Oct 2016 13:57:16 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 39571 Received: (qmail 27328 invoked from network); 5 Oct 2016 13:57:16 -0000 X-Qmail-Scanner-Diagnostics: from mailout1.w1.samsung.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(210.118.77.11):SA:0(-2.6/5.0):. Processed in 0.571269 secs); 05 Oct 2016 13:57:16 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=RP_MATCHES_RCVD autolearn=unavailable autolearn_force=no version=3.4.1 X-Envelope-From: p.stephenson@samsung.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: none (ns1.primenet.com.au: domain at samsung.com does not designate permitted sender hosts) X-AuditID: cbfec7f4-f791c6d000006eac-52-57f5045a0006 Date: Wed, 05 Oct 2016 14:47:03 +0100 From: Peter Stephenson To: Zsh hackers list Subject: Re: 'set -e' with '!' POSIX issue Message-id: <20161005144703.12fdf6c4@pwslap01u.europe.root.pri> In-reply-to: <4e660f18-3850-d589-8a17-e75d2c419fbe@inlv.org> Organization: Samsung Cambridge Solution Centre X-Mailer: Claws Mail 3.7.9 (GTK+ 2.22.0; i386-redhat-linux-gnu) MIME-version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrDIsWRmVeSWpSXmKPExsWy7djP87pRLF/DDR78s7E42PyQyYHRY9XB D0wBjFFcNimpOZllqUX6dglcGYu/PmMtWKVV8WjNBeYGxvnyXYwcHBICJhI73nh0MXICmWIS F+6tZ+ti5O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XsJTY0fwCr5xSwkbh2Yx07xMxLTBK3H1iB2PwC+hJX /35igrjOXmLmlTOMEL2CEj8m3wObwww0c/O2JlYIW15i85q3UHeqS9y4u5t9AqPwLCQts5C0 zELSsoCReRWjSGppcW56brGRXnFibnFpXrpecn7uJkZgDG079nPLDsaud8GHGAU4GJV4eDs2 fw4XYk0sK67MPcQowcGsJMIbzPw1XIg3JbGyKrUoP76oNCe1+BCjKTBgJjJLiSbnA+M7ryTe 0MTQ3NLQyNjCwtzISEmcd+qHK+FCAumJJanZqakFqUUwfUwcnFINjCt+7npzd8vlxOCWb7N4 3s2I7zmfsjUteZ/6+6oXn/zKbhbq668xi/G/FFXNb39Qp6GUO+Ta+lXaFS1n30/buSONl23L YtOgM5zLVD4zGD/lDn+98PP8xav0NK1i/IWm8z3e+fHgq6fTg55ctJzWqBgrtWr1Z7//EX08 BT3VFw5sLsp5eUtnkp8SS3FGoqEWc1FxIgDwF+8MtwIAAA== X-MTR: 20000000000000000@CPGS X-CMS-MailID: 20161005134706eucas1p189d96af515106b2c23b3206f934baff5 X-Msg-Generator: CA X-Sender-IP: 182.198.249.180 X-Local-Sender: =?UTF-8?B?UGV0ZXIgU3RlcGhlbnNvbhtTQ1NDLURhdGEgUGxhbmUb?= =?UTF-8?B?7IK87ISx7KCE7J6QG1ByaW5jaXBhbCBFbmdpbmVlciwgU29mdHdhcmU=?= X-Global-Sender: =?UTF-8?B?UGV0ZXIgU3RlcGhlbnNvbhtTQ1NDLURhdGEgUGxhbmUbU2Ft?= =?UTF-8?B?c3VuZyBFbGVjdHJvbmljcxtQcmluY2lwYWwgRW5naW5lZXIsIFNvZnR3YXJl?= X-Sender-Code: =?UTF-8?B?QzEwG0VIURtDMTBDRDA1Q0QwNTAwNTg=?= CMS-TYPE: 201P X-HopCount: 7 X-CMS-RootMailID: 20161004075413eucas1p2cf7a0e3dded0a894b79c661f6da0b885 X-RootMTR: 20161004075413eucas1p2cf7a0e3dded0a894b79c661f6da0b885 References: <70cf25f2-f156-51c4-60b6-00def8769328@inlv.org> <20161002185530.3fa8c013@ntlworld.com> <20161004074538.GD4212@cventin.lip.ens-lyon.fr> <20161004093005.7dbc6696@pwslap01u.europe.root.pri> <4e660f18-3850-d589-8a17-e75d2c419fbe@inlv.org> On Wed, 5 Oct 2016 12:18:26 +0200 Martijn Dekker wrote: > On Tue, Mar 17, 2009 at 12:46:20PM +0100, Vincent Lefevre wrote: > > POSIX shells (bash, dash, ksh93, pdksh, posh) return with no output > > and an exit status equal to 1 on: > > > > sh -c 'set -e; foo() { false && false; }; foo; echo $?' > > > > but zsh doesn't, even with "emulate sh": > > > > $ zsh -fc 'emulate sh; set -e; foo() { false && false; }; foo; echo $?' > > 1 I think this is a bug, regardless of the standard. The "&&" within the function shouldn't have anything to do with what happens outside, and it works without that. The fix appears to be similar to the one for "!". Please reassure me that this is correct: % ./zsh -fc 'set -e; foo() { false && false; echo OK; }; foo; echo $?' OK 0 We hit the first "false" in the &&, which doesn't trigger ERR_EXIT so the second "false" that would is never executed; therefore we proceed to "echo OK"; therefore the status of the function is 0. If there's no controversy I may add this as a test case for future reference, together with the "true & false" case that causes the function to be aborted. pws diff --git a/Src/exec.c b/Src/exec.c index 741c80e..c0ed2c4 100644 --- a/Src/exec.c +++ b/Src/exec.c @@ -1229,7 +1229,7 @@ execlist(Estate state, int dont_change_job, int exiting) } while (wc_code(code) == WC_LIST && !breaks && !retflag && !errflag) { int donedebug; - int this_noerrexit = 0; + int this_noerrexit = 0, this_donetrap = 0; ltype = WC_LIST_TYPE(code); csp = cmdsp; @@ -1353,10 +1353,10 @@ execlist(Estate state, int dont_change_job, int exiting) /* We've skipped to the end of the list, not executing * * the final pipeline, so don't perform error handling * * for this sublist. */ - donetrap = 1; + this_donetrap = 1; goto sublist_done; } else if (WC_SUBLIST_TYPE(code) == WC_SUBLIST_END) { - donetrap = 1; + this_donetrap = 1; /* * Treat this in the same way as if we reached * the end of the sublist normally. @@ -1386,10 +1386,10 @@ execlist(Estate state, int dont_change_job, int exiting) /* We've skipped to the end of the list, not executing * * the final pipeline, so don't perform error handling * * for this sublist. */ - donetrap = 1; + this_donetrap = 1; goto sublist_done; } else if (WC_SUBLIST_TYPE(code) == WC_SUBLIST_END) { - donetrap = 1; + this_donetrap = 1; /* * Treat this in the same way as if we reached * the end of the sublist normally. @@ -1439,7 +1439,7 @@ sublist_done: /* Check whether we are suppressing traps/errexit * * (typically in init scripts) and if we haven't * * already performed them for this sublist. */ - if (!noerrexit && !this_noerrexit && !donetrap) { + if (!noerrexit && !this_noerrexit && !donetrap && !this_donetrap) { if (sigtrapped[SIGZERR] && lastval) { dotrap(SIGZERR); donetrap = 1; diff --git a/Test/C03traps.ztst b/Test/C03traps.ztst index 0faec02..5057dcf 100644 --- a/Test/C03traps.ztst +++ b/Test/C03traps.ztst @@ -476,7 +476,7 @@ fi } fn -0:ERRRETURN not triggered in if condition +0:ERR_RETURN not triggered in if condition >Oh, yes fn() { @@ -490,7 +490,7 @@ fi } fn -1:ERRRETURN in "if" +1:ERR_RETURN in "if" fn() { emulate -L zsh @@ -503,7 +503,7 @@ fi } fn -1:ERRRETURN in "else" branch (regression test) +1:ERR_RETURN in "else" branch (regression test) $ZTST_testdir/../Src/zsh -f =(<<<" if false; then @@ -515,7 +515,7 @@ print Yes fi ") -0:ERRRETURN when false "if" is the first statement in an "else" (regression) +0:ERR_RETURN when false "if" is the first statement in an "else" (regression) >Yes F:Must be tested with a top-level script rather than source or function @@ -527,7 +527,7 @@ F:Must be tested with a top-level script rather than source or function print after } fn -1:ERRRETURN, basic case +1:ERR_RETURN, basic case >before fn() { @@ -539,7 +539,7 @@ F:Must be tested with a top-level script rather than source or function print after } fn -0:ERRETURN with "!" +0:ERR_RETURN with "!" >before >after @@ -553,7 +553,7 @@ F:Must be tested with a top-level script rather than source or function print after } fn -1:ERRETURN with "!" and a following false +1:ERR_RETURN with "!" and a following false >before fn() { @@ -566,7 +566,7 @@ F:Must be tested with a top-level script rather than source or function print after } fn -0:ERRETURN with "!" suppressed inside complex structure +0:ERR_RETURN with "!" suppressed inside complex structure >before >after @@ -580,9 +580,22 @@ F:Must be tested with a top-level script rather than source or function print after } fn -1:ERRETURN with no "!" suppression (control case) +1:ERR_RETURN with no "!" suppression (control case) >before + (setopt err_return + fn() { + print before-in + false && false + } + print before-out + fn + print after-out + ) +1:ERR_RETURN with "&&" in function (regression test) +>before-out +>before-in + %clean rm -f TRAPEXIT