From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29606 invoked by alias); 10 Nov 2016 10:08:02 -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: 39901 Received: (qmail 7398 invoked from network); 10 Nov 2016 10:08:02 -0000 X-Qmail-Scanner-Diagnostics: from mailout3.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.13):SA:0(-2.9/5.0):. Processed in 0.517647 secs); 10 Nov 2016 10:08:02 -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.9 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: cbfec7f1-f79f46d0000008eb-0a-5824449fc58b Date: Thu, 10 Nov 2016 09:57:47 +0000 From: Peter Stephenson To: zsh-workers@zsh.org Subject: Re: exit trap and list pipelines Message-id: <20161110095747.27f30e3f@pwslap01u.europe.root.pri> In-reply-to: <161109211957.ZM4353@torch.brasslantern.com> 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+NgFnrNIsWRmVeSWpSXmKPExsWy7djPc7rzXVQiDCYcYLM42PyQyYHRY9XB D0wBjFFcNimpOZllqUX6dglcGe0zr7AXXBGuWPTlE2MD40z+LkZODgkBE4lFK+6xQdhiEhfu rQeyuTiEBJYyShx8+JMR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KHHmx0ewm/gF9CWu /v0EdZ+9xMwrZxghegUlfky+BzaTWUBLYvO2JlYIW15i85q3zCC2kIC6xI27u9knMArPQtIy C0nLLCQtCxiZVzGKpJYW56bnFhvqFSfmFpfmpesl5+duYgTG0bZjPzfvYLy0MfgQowAHoxIP b4emcoQQa2JZcWXuIUYJDmYlEV5VR5UIId6UxMqq1KL8+KLSnNTiQ4ymwICZyCwlmpwPjPG8 knhDE0NzS0MjYwsLcyMjJXHekg9XwoUE0hNLUrNTUwtSi2D6mDg4pRoYjWftPHiEYeOP21O0 rjzYxbTrqKKr8OeuPZLCidnbTDh0gnubbXJVna5NjClp5Nwe0WrHOKM7ccO2CV66URekilMX PzpQOXXy3947DTUTdcs7c6Zemq7pf9rzqdmm3oyLC4J/ND/UuHzj3NaMzpUz1rP9V/nql3Dw wsvnW+RMrpRe9rzT6SQ3X4mlOCPRUIu5qDgRAPzjTpu5AgAA X-MTR: 20000000000000000@CPGS X-CMS-MailID: 20161110095750eucas1p21ee561366d170e424ad94d30666bd0bb X-Msg-Generator: CA X-Sender-IP: 182.198.249.179 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: 20161110052050epcas5p266e10f9f640badaf6139477bb39d49b8 X-RootMTR: 20161110052050epcas5p266e10f9f640badaf6139477bb39d49b8 References: <1478745377.2440153.783050761.5D9FA45B@webmail.messagingengine.com> <161109211957.ZM4353@torch.brasslantern.com> On Wed, 9 Nov 2016 21:19:57 -0800 Bart Schaefer wrote: > On Nov 9, 9:36pm, Anthony Heading wrote: > } > } Printing '6' here seems wrong? I think it didn't some years back. > } > } % zsh -c 'trap "echo hello" EXIT; { :; } | wc -c' > } 6 > } hello > > zsh-2.6 and zsh-3.0 yeild 0, zsh-4.3.17 prints 6. > > The change occured because, where zsh formerly would note that the > right side was an external command and "exec" it (thereby disabling > the exit trap), newer zsh notices that there is a trap and does > another fork so that the trap can execute after wc finishes. This > means that both sides of the pipe run the trap, whereas before > (and in bash) only one side does so. I think, therefore, we can just suppress it on the left hand side of the pipe. The case where the LHS is a shell construct is special, so I suppose it just needs extra treatment. I've added a test for the other case but it was already working. This shouldn't affect EXIT traps in functions as you need to set them inside the function in question. The fact I've replaced wc on the right with a shell construct in the test doesn't affect this bug, because we've already forked for the LHS, but it's arguably a different case to having an external command on the right. In practice I don't think we're sensitive to the difference. pws diff --git a/Src/exec.c b/Src/exec.c index c0ed2c4..a01a633 100644 --- a/Src/exec.c +++ b/Src/exec.c @@ -1888,6 +1888,10 @@ execpline2(Estate state, wordcode pcode, entersubsh(((how & Z_ASYNC) ? ESUB_ASYNC : 0) | ESUB_PGRP | ESUB_KEEPTRAP); close(synch[1]); + if (sigtrapped[SIGEXIT]) + { + unsettrap(SIGEXIT); + } execcmd_exec(state, &eparams, input, pipes[1], how, 1); _exit(lastval); } diff --git a/Test/C03traps.ztst b/Test/C03traps.ztst index 828a3d1..c3bedb0 100644 --- a/Test/C03traps.ztst +++ b/Test/C03traps.ztst @@ -641,6 +641,23 @@ F:Must be tested with a top-level script rather than source or function >TERM >EXIT + # Should not get "hello" in the single quotes. + ( + trap "echo hello" EXIT; + { :; } | { read line; print "'$line'"; } + ) +0:EXIT trap not called in LHS of pipeline: Shell construct on LHS +>'' +>hello + + ( + trap "echo hello" EXIT; + cat '' +>hello + %clean rm -f TRAPEXIT