From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: zsh-workers-return-43669-ml=inbox.vuxu.org@zsh.org X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,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 d83c45ac for ; Wed, 10 Oct 2018 09:31:37 +0000 (UTC) Received: (qmail 1274 invoked by alias); 10 Oct 2018 09:31:26 -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: 43669 Received: (qmail 10154 invoked by uid 1010); 10 Oct 2018 09:31:26 -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(-7.2/5.0):. Processed in 1.991877 secs); 10 Oct 2018 09:31:26 -0000 X-Envelope-From: p.stephenson@samsung.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20181010093118euoutp0137fbbd78d6ff8aaf79629732e95c0f0d~cNWSeTcMK0449804498euoutp01T DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1539163878; bh=9nAoAVslgskQUXFTNjJJJCBgRrgX9REu30SnhvOpEZQ=; h=Subject:From:To:Date:In-Reply-To:References:From; b=Uq/1u84MM98e3NOUaU4ELTzaEBRrVvG/ZVBM0arUAffwEXQ3sTfj/xdQ49TTo0WAs ofBr0US3pzplE+cxyOFT3RPmqkrRRGy0SZ5Ubebdx0duUQHTr8o+PSvgkrqaNl5pat rngu8SEUte7xKO+UeA7+o7gxbSYPMs4dkDeyzl9s= X-AuditID: cbfec7f2-a1ae89c000001159-dc-5bbdc6e567c3 Subject: Re: [Bug] Exiting shell from function called by trap handler always produces status 0 From: Peter Stephenson To: Date: Wed, 10 Oct 2018 10:31:15 +0100 In-Reply-To: <1539161816.1671477.1536960968.146F809C@webmail.messagingengine.com> X-Mailer: Evolution 3.18.5.2-0ubuntu3.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrLIsWRmVeSWpSXmKPExsWy7djP87pPj+2NNlg2V8PiYPNDJgdGj1UH PzAFMEZx2aSk5mSWpRbp2yVwZWxaOpOp4LtYxa2F51kbGO8JdTFyckgImEj8PLScrYuRi0NI YAWjxIZZG5ggnD4mieYjM1kgnF4miY+fDrHDtGzZOIsFxBYSWM4o0XiGC65oz4yrzBDOGUaJ 119/Ac3iAHIuMEqsAmsWFkiQePKlHayZTcBQYuqm2YwgtoiApMS15tNgNouAqkRL+05mEJtT IFBixZmFTBCLNSQ23DwGZvMKCEqcnPkEbA6zgLxE89bZYHslBB6zSVw608gMUVQmcXztJEaI ZheJ1Xefs0DYwhKvjm+B+kZG4vTkHhaI5nZGiTWTXrNDOD2MEpuO3oHqtpbou32REeQbZgFN ifW79CHCjhKvpt9mAQlLCPBJ3HgrCHEQn8SkbdOZIcK8Eh1t0LBWk9jRtJURIiwj8XSNwgRG pVlIvpmF5JtZCKsWMDKvYhRPLS3OTU8tNsxLLdcrTswtLs1L10vOz93ECEwEp/8d/7SD8eul pEOMAhyMSjy8DRf2RAuxJpYVV+YeYpTgYFYS4b11eG+0EG9KYmVValF+fFFpTmrxIUZpDhYl cd5l8zZGCwmkJ5akZqemFqQWwWSZODilGhhXr12wufybg0666B1Xzn1mrS3tC/Wy/21aUPR3 psm9ogDGxS/upiy9vWrxrP9vde4IBgtElDko2YucfzjH4E6+5JHH59OTP3V9sHjtzMTEt+iU YplKX9KBL14dfS03YiV3s27bwOKkKbcmZk+GffLlvtIL3iUzypKdejJbAy9smtFoWJlg2aTE UpyRaKjFXFScCAD/QdvbAAMAAA== X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpikeLIzCtJLcpLzFFi42I5/e/4Pd0nx/ZGG3yZoG1xsPkhkwOjx6qD H5gCGKP0bIryS0tSFTLyi0tslaINLYz0DC0t9IxMLPUMjc1jrYxMlfTtbFJSczLLUov07RL0 MjYtnclU8F2s4tbC86wNjPeEuhg5OSQETCS2bJzF0sXIxSEksJRR4vzMRewQCRmJT1c+QtnC En+udbFBFHUzScz6tJ0VJCEkcIZRYvVtRojEBUaJNcv+giV4BQwlvs9dwQxiCwskSDz50s4C YrMBxadums0IYosISEpcaz4NZrMIqEq0tO8Eq+cUCJRYcWYhE8TQ6SwS/7vPgyWYBTQlWrf/ hjpJQ2LDzWNMEMsEJU7OfMICUSMv0bx1NvMERqFZSFpmISmbhaRsASPzKkaR1NLi3PTcYkO9 4sTc4tK8dL3k/NxNjMDw33bs5+YdjJc2Bh9iFOBgVOLhbbiwJ1qINbGsuDL3EKMEB7OSCO+t w3ujhXhTEiurUovy44tKc1KLDzGaAn00kVlKNDkfGJt5JfGGpobmFpaG5sbmxmYWSuK85w0q o4QE0hNLUrNTUwtSi2D6mDg4pRoY3Zfsiew517NxO//uF2o8Sx+YM07KVE6Qvn2x7mpTxe/1 fa63+zNzBAx/9mcsLjr/Zf421VrhdU5an1WCTiy/a6CtNl1efnHHdqF5ZfKmTBecJcva33d2 vN/jVfl785ZJAVVlEb8PnVZfklbH0mmygMNMJ/510OTwR6Flb28FzbUQj+mY2PZZiaU4I9FQ i7moOBEAGVaBqJUCAAA= Message-Id: <20181010093117eucas1p1ea07edfcb685e79ff93401dcaf8ceae1~cNWQtdMVN2346923469eucas1p1S@eucas1p1.samsung.com> X-CMS-MailID: 20181010093117eucas1p1ea07edfcb685e79ff93401dcaf8ceae1 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20181009012624epcas1p44f2ae223f663713a980af4be735e5a3f X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20181009012624epcas1p44f2ae223f663713a980af4be735e5a3f References: <20181009084918eucas1p27dedda10d51beb773ba9175967912d2c~b5IUtvcVK3037630376eucas1p2R@eucas1p2.samsung.com> <205ea5e4-4dc9-2ebf-9437-0822195e1a9a@inlv.org> <20181009131646eucas1p2eb07d8fa34e97de25db60d6a56c584a4~b8x2n0O1S2407324073eucas1p2z@eucas1p2.samsung.com> <20181009210912.7a17eb77@pws-HP.localdomain> <1539161816.1671477.1536960968.146F809C@webmail.messagingengine.com> On Wed, 2018-10-10 at 08:56 +0000, Daniel Shahaf wrote: > Peter Stephenson wrote on Tue, 09 Oct 2018 21:09 +0100: > >  > > Here's a slight improvement --- we can "exit 0" even if the last command > > status is non-zero. > Can we add a test for this?  I tried to write one but couldn't nail down > the behaviour that differed. >  > FWIW: >  > % Src/zsh -fc 'fn() { exit 0 }; trap fn EXIT; false'  ; echo $? > 1 > % /usr/bin/zsh -fc 'fn() { exit 0 }; trap fn EXIT; false' ; echo $? > 0 > %  I missed another case for implicit exit that was masking the effect.  We go through zexit() at this point as it's a standard end-of-command-list case, though whether that's actually necessary (running additional tests mostly associated with interactive shells) I don't know. It's also a bit confusing that the exit trap has already happened in that point --- in execlist(), I think --- even though it's more sensibly associated in this case with the code inside zexit() which will also run it (and if it had done the exit status would have been overridden and we wouldn't have seen this).  But I don't think there are any real world consequences for this with this change. I don't think an exit_pending can actually be picked up at that point, but it's easier and safer to be consistent. pws diff --git a/Src/builtin.c b/Src/builtin.c index e01e035..8dcdcc0 100644 --- a/Src/builtin.c +++ b/Src/builtin.c @@ -5723,7 +5723,7 @@ int exit_val;  void  realexit(void)  { -    exit(exit_val ? exit_val : lastval); +    exit((shell_exiting || exit_pending) ? exit_val : lastval);  }    /* As realexit(), but call _exit instead */ @@ -5732,7 +5732,7 @@ realexit(void)  void  _realexit(void)  { -    _exit(exit_val ? exit_val : lastval); +    _exit((shell_exiting || exit_pending) ? exit_val : lastval);  }    /* exit the shell.  val is the return value of the shell.  * diff --git a/Src/init.c b/Src/init.c index 838c2c2..cec9143 100644 --- a/Src/init.c +++ b/Src/init.c @@ -1358,7 +1358,7 @@ init_misc(char *cmd, char *zsh_name)   bshin = fdopen(SHIN, "r");   execstring(cmd, 0, 1, "cmdarg");   stopmsg = 1; - zexit(exit_val ? exit_val : lastval, 0); + zexit((exit_pending || shell_exiting) ? exit_val : lastval, 0);      }        if (interact && isset(RCS)) diff --git a/Test/C03traps.ztst b/Test/C03traps.ztst index bab0b0a..57daf8d 100644 --- a/Test/C03traps.ztst +++ b/Test/C03traps.ztst @@ -872,6 +872,9 @@ F:Must be tested with a top-level script rather than source or function    $ZTST_testdir/../Src/zsh -fc 'fn() { exit 13; }; trap fn EXIT'  13:Explicit exit in exit trap overrides implicit exit status   +  $ZTST_testdir/../Src/zsh -fc 'fn() { exit 0; }; trap fn EXIT; false' +0:Explicit exit status 0 in exit trap overrides implicit non-zero status +  %clean      rm -f TRAPEXIT