From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from primenet.com.au (ns1.primenet.com.au [203.24.36.2]) by inbox.vuxu.org (OpenSMTPD) with ESMTP id 8df44b38 for ; Tue, 17 Dec 2019 20:30:12 +0000 (UTC) Received: (qmail 21091 invoked by alias); 17 Dec 2019 20:30:04 -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: List-Unsubscribe: X-Seq: 45072 Received: (qmail 22405 invoked by uid 1010); 17 Dec 2019 20:30:04 -0000 X-Qmail-Scanner-Diagnostics: from know-smtprelay-omc-10.server.virginmedia.net by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.102.1/25663. spamassassin: 3.4.2. Clear:RC:0(80.0.253.74):SA:0(-2.0/5.0):. Processed in 3.282354 secs); 17 Dec 2019 20:30:04 -0000 X-Envelope-From: p.w.stephenson@ntlworld.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at _smtprelay.virginmedia.com designates 80.0.253.74 as permitted sender) X-Originating-IP: [86.16.88.158] X-Authenticated-User: p.w.stephenson@ntlworld.com X-Spam: 0 X-Authority: v=2.3 cv=Dvd4Bl3+ c=1 sm=1 tr=0 a=MiHCjVqLJ44lE3bxSlffFQ==:117 a=MiHCjVqLJ44lE3bxSlffFQ==:17 a=jpOVt7BSZ2e4Z31A5e1TngXxSK0=:19 a=IkcTkHD0fZMA:10 a=Jtdkn_J4kgtqKjT3yJwA:9 a=QEXdDO2ut3YA:10 Message-ID: Subject: Re: Bug with traps and exit From: Peter Stephenson To: zsh-workers@zsh.org Date: Tue, 17 Dec 2019 20:29:18 +0000 In-Reply-To: <20191217073114.sgt4skm3zixuwsfd@tarpaulin.shahaf.local2> References: <1576145690.8441.3.camel@samsung.com> <46f2fc10-2f2c-88f1-e4e2-87196a39a37a@inlv.org> <1576248580.5214.17.camel@samsung.com> <20191214112826.4klmtvxvuhioddcf@tarpaulin.shahaf.local2> <20191216052423.svgnhfkpsxh46a6j@tarpaulin.shahaf.local2> <20191217073114.sgt4skm3zixuwsfd@tarpaulin.shahaf.local2> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.28.5-0ubuntu0.18.04.1 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit X-CMAE-Envelope: MS4wfNOEPn+pQ587/CT+x+7W41+VH/4XtIGM8SDmlpUD2qcirWF2VCZlQald9Ry/9YRfBIAvgEV0AmhV7lVq5Ys+1elEXm1/j1Nm7g/o3Y97PcIO96glTD38 OrmHJPrYn/yzqn0joHWC+3Kt5D8W4Av6QNyBTG2MgXzNdnt6UflgrZ8w On Tue, 2019-12-17 at 07:31 +0000, Daniel Shahaf wrote: >Bart Schaefer wrote on Sun, Dec 15, 2019 at 22:37:53 -0800: >>On Sun, Dec 15, 2019 at 9:25 PM Daniel Shahaf wrote: >>> >>> workers/44007 (also in this thread): >>> >>>> trap 'printf $1; exit; printf $2' USR1 >>>> fn() { >>>> printf 1 >>>> kill -s usr1 $$ >>>> printf 2 >>>> } >>>> printf 0 >>>> fn A B >>>> printf 3 >>> >>> Here, Martijn was saying that zsh should print 01A but in fact prints 01A2. ..... > - exit_pending is set > > - The remainder of the trap is skipped (I assume that's because > bin_break() set retflag?) > > - The remainder of fn() is executed I guess this is where the problem is. We should presumably continue to skip through the function, too. We may be reesetting "breaks" when we shouldn't be, for example, or failing to propagate some other condition, perhaps just the effect of the exit_pending. >> The trouble is that we also have to treat differently the cases of the >> trap having been set inside the function, and the trap existing >> outside the function when the function is called. > > Why? I'm not sure that's necessarily ture of USR1 traps --- I can't think of why the *effect* would be different, even if the trap is local to the function --- but one of our big headaches is EXIT traps which in zsh are triggered at the end of the enclosing context. (An exit in an exit trap is even worse). Luckily, we don't have to deal with exit traps in this case, but we do have to be sure we're not doing anything that will have a knock-on effect there. pws