From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2942 invoked by alias); 4 Mar 2016 18:02:22 -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: 38094 Received: (qmail 25624 invoked from network); 4 Mar 2016 18:02:19 -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: cbfec7f4-f79026d00000418a-32-56d9cda55b20 Date: Fri, 04 Mar 2016 18:02:11 +0000 From: Peter Stephenson To: zsh-workers@zsh.org Subject: Re: [BUG] Sticky-sh POSIX_TRAPS are function-local Message-id: <20160304180211.438683be@pwslap01u.europe.root.pri> In-reply-to: <56CF0718.8060708@inlv.org> References: <56C15DF1.8080405@inlv.org> <20160216095744.52cb8389@pwslap01u.europe.root.pri> <56C3B2E7.1090806@inlv.org> <20160225115339.7688264a@pwslap01u.europe.root.pri> <56CF0718.8060708@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/xq7pLz94MM/jeYm5xsPkhkwOjx6qD H5gCGKO4bFJSczLLUov07RK4Mjbe62IqWChUMfHXEvYGxvO8XYycHBICJhKfv65khLDFJC7c W8/WxcjFISSwlFFi+sVDLCAJIYEZTBJnl5VAJE4zSmx8Po0FwjnDKNG1vZ+1i5GDg0VAVWLm zwyQBjYBQ4mpm2aDTRUREJc4u/Y82CBhAWuJM1sWMIHYvAL2EjO2PWcDsTkFNCQm919ngph5 llFi/7ObzCAJfgF9iat/PzFBnGcvMfPKGUaIZkGJH5PvgQ1lFtCS2LytiRXClpfYvOYtM8TV 6hI37u5mn8AoPAtJyywkLbOQtCxgZF7FKJpamlxQnJSea6hXnJhbXJqXrpecn7uJERLOX3Yw Lj5mdYhRgINRiYf3RsP1MCHWxLLiytxDjBIczEoivGt33wwT4k1JrKxKLcqPLyrNSS0+xCjN waIkzjt31/sQIYH0xJLU7NTUgtQimCwTB6dUAyNf02f3l9OFGz6vfuoVsHWHXKPBrVNHmr9O PRvY2ZbZbvfrZm3Lr9Q3BXJtaae/zZl7eumbm1+iBKbuuHxoYZHiZp6OrshYzzVJUtFLJlry iD+Y1rVK6LBFt+DCN1uMltrPry3evnHHz6SwsM5y5x/z9j2KaUlyq/+sqDFb8e2MKRu+31xu +75biaU4I9FQi7moOBEAQu0adWMCAAA= On Thu, 25 Feb 2016 14:52:24 +0100 Martijn Dekker 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