From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2370 invoked by alias); 25 Feb 2016 12:03:51 -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: 38024 Received: (qmail 27471 invoked from network); 25 Feb 2016 12:03:48 -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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.1 X-AuditID: cbfec7f5-f79b16d000005389-04-56ceeb4601c2 Date: Thu, 25 Feb 2016 11:53:39 +0000 From: Peter Stephenson To: zsh-workers@zsh.org Subject: Re: [BUG] Sticky-sh POSIX_TRAPS are function-local Message-id: <20160225115339.7688264a@pwslap01u.europe.root.pri> In-reply-to: <56C3B2E7.1090806@inlv.org> References: <56C15DF1.8080405@inlv.org> <20160216095744.52cb8389@pwslap01u.europe.root.pri> <56C3B2E7.1090806@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+NgFrrALMWRmVeSWpSXmKPExsVy+t/xy7pur8+FGeyerWRxsPkhkwOjx6qD H5gCGKO4bFJSczLLUov07RK4Mh6tnspaMFmgovd7K3sD43qeLkZODgkBE4k78y4wQthiEhfu rWfrYuTiEBJYyijxp2EVK4Qzg0nixd3ZUM45RolVb16xQzhnGSVOXN3DBtLPIqAq8fvCD1YQ m03AUGLqptlgc0UExCXOrj3PAmILC1hLnNmygAnE5hWwl9i99AOYzSmgIXHq/XPmLkYOoKGV El23Y0DC/AL6Elf/fmKCOM9eYuaVM4wQrYISPybfAxvJLKAlsXlbEyuELS+xec1bZhBbSEBd 4sbd3ewTGIVnIWmZhaRlFpKWBYzMqxhFU0uTC4qT0nON9IoTc4tL89L1kvNzNzFCwvnrDsal x6wOMQpwMCrx8DL8PBsmxJpYVlyZe4hRgoNZSYR36YtzYUK8KYmVValF+fFFpTmpxYcYpTlY lMR5Z+56HyIkkJ5YkpqdmlqQWgSTZeLglGpgrH5+5Pcry1sCmsz3VcvvBRcpsGQkFt7c47z9 5BWzP0E3H55dt/+gsusCNt7+MM0dkxfF7UmtTZJMaDAse7WgVOMHt1RHuf/My6cZpY99y129 9HdZz4Vim9NrGT3U5DzMGKfkyn16rnOHaY3t5YkuCVNiHM75G1qxnxE9uHTtx9p3itsm/bm6 S4mlOCPRUIu5qDgRAFco/7ZjAgAA On Wed, 17 Feb 2016 00:38:15 +0100 Martijn Dekker wrote: > However, since POSIX traps are inherently global, the expectation that > POSIX traps wipe out previous traps only applies to global traps. Could > you make an exception for function-local traps? I think this makes nested native mode EXIT traps work while preserving a global POSIX mode EXIT trap. pws diff --git a/Src/signals.c b/Src/signals.c index 32452ae..1344395 100644 --- a/Src/signals.c +++ b/Src/signals.c @@ -920,9 +920,14 @@ removetrap(int sig) * Note that we save the trap here even if there isn't an existing * one, to aid in removing this one. However, if there's * already one at the current locallevel we just overwrite it. + * + * Note we save EXIT traps based on the *current* setting of + * POSIXTRAPS --- so if there is POSIX EXIT trap set but + * we are in native mode it can be saved, replaced by a function + * trap, and then restored. */ if (!dontsavetrap && - (sig == SIGEXIT ? !exit_trap_posix : isset(LOCALTRAPS)) && + (sig == SIGEXIT ? !isset(POSIXTRAPS) : isset(LOCALTRAPS)) && locallevel && (!trapped || locallevel > (sigtrapped[sig] >> ZSIG_SHIFT))) dosavetrap(sig, locallevel); diff --git a/Test/C03traps.ztst b/Test/C03traps.ztst index d8183a4..f4466b5 100644 --- a/Test/C03traps.ztst +++ b/Test/C03traps.ztst @@ -419,6 +419,23 @@ >end of program >EXIT TRAP TRIGGERED + (cd ..; $ZTST_exe -fc ' + echo entering program + emulate sh -c '\''trap "echo POSIX exit trap triggered" EXIT'\'' + fn() { + trap "echo native zsh function-local exit trap triggered" EXIT + echo entering native zsh function + } + fn + echo exiting program + ') +0:POSX EXIT trap can have nested native mode EXIT trap +>entering program +>entering native zsh function +>native zsh function-local exit trap triggered +>exiting program +>POSIX exit trap triggered + (set -e printf "a\nb\n" | while read line do