zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.stephenson@samsung.com>
To: zsh-workers@zsh.org
Subject: Re: [BUG] Sticky-sh POSIX_TRAPS are function-local
Date: Thu, 25 Feb 2016 11:53:39 +0000	[thread overview]
Message-ID: <20160225115339.7688264a@pwslap01u.europe.root.pri> (raw)
In-Reply-To: <56C3B2E7.1090806@inlv.org>

On Wed, 17 Feb 2016 00:38:15 +0100
Martijn Dekker <martijn@inlv.org> 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


  parent reply	other threads:[~2016-02-25 12:03 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-15  5:11 Martijn Dekker
2016-02-16  9:57 ` Peter Stephenson
2016-02-16 12:46   ` Peter Stephenson
2016-02-16 23:38   ` Martijn Dekker
2016-02-17  4:25     ` Bart Schaefer
2016-02-17  5:24       ` Martijn Dekker
2016-02-19 18:59         ` Bart Schaefer
2016-02-17 10:36     ` Peter Stephenson
2016-02-25 11:53     ` Peter Stephenson [this message]
2016-02-25 13:52       ` Martijn Dekker
2016-02-25 14:17         ` Peter Stephenson
2016-03-04 18:02         ` Peter Stephenson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160225115339.7688264a@pwslap01u.europe.root.pri \
    --to=p.stephenson@samsung.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).