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: Fri, 04 Mar 2016 18:02:11 +0000	[thread overview]
Message-ID: <20160304180211.438683be@pwslap01u.europe.root.pri> (raw)
In-Reply-To: <56CF0718.8060708@inlv.org>

On Thu, 25 Feb 2016 14:52:24 +0100
Martijn Dekker <martijn@inlv.org> wrote:
> But if a function defined with sticky emulation sets a POSIX trap, and
> that function is called from native zsh, then the old behaviour returns
> and a subsequent function-local trap wipes out the global POSIX trap. So
> this still kills my POSIX library functions that set a trap.

It looks like I've figured this out.

pws

diff --git a/Src/signals.c b/Src/signals.c
index 1344395..2eefc07 100644
--- a/Src/signals.c
+++ b/Src/signals.c
@@ -877,16 +877,21 @@ settrap(int sig, Eprog l, int flags)
             sig != SIGCHLD)
             install_handler(sig);
     }
+    sigtrapped[sig] |= flags;
     /*
      * Note that introducing the locallevel does not affect whether
      * sigtrapped[sig] is zero or not, i.e. a test without a mask
      * works just the same.
      */
-    sigtrapped[sig] |= (locallevel << ZSIG_SHIFT) | flags;
     if (sig == SIGEXIT) {
 	/* Make POSIX behaviour of EXIT trap sticky */
 	exit_trap_posix = isset(POSIXTRAPS);
+	/* POSIX exit traps are not local. */
+	if (!exit_trap_posix)
+	    sigtrapped[sig] |= (locallevel << ZSIG_SHIFT);
     }
+    else
+	sigtrapped[sig] |= (locallevel << ZSIG_SHIFT);
     unqueue_signals();
     return 0;
 }
--- a/Test/C03traps.ztst
+++ b/Test/C03traps.ztst
@@ -429,14 +429,32 @@
      fn
      echo exiting program
    ')
-0:POSX EXIT trap can have nested native mode EXIT trap
+0:POSIX 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
+   (cd ..; $ZTST_exe -fc '
+     echo entering program
+     emulate sh -c '\''spt() { trap "echo POSIX exit trap triggered" EXIT; }'\''
+     fn() {
+	trap "echo native zsh function-local exit trap triggered" EXIT
+	echo entering native zsh function
+     }
+     spt
+     fn
+     echo exiting program
+   ')
+0:POSIX EXIT trap not replaced if defined within function
+>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
        [[ $line = a* ]] || continue


      parent reply	other threads:[~2016-03-04 18:02 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
2016-02-25 13:52       ` Martijn Dekker
2016-02-25 14:17         ` Peter Stephenson
2016-03-04 18:02         ` Peter Stephenson [this message]

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=20160304180211.438683be@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).