1
0
mirror of git://git.code.sf.net/p/zsh/code synced 2024-09-28 15:01:21 +02:00

38094: Fix POSIX EXIT traps defined in function.

These aren't local, so set the local level to 0; else they can get
overridden incorrectly.
This commit is contained in:
Peter Stephenson 2016-03-07 09:42:21 +00:00
parent bc958ab275
commit 17fb014dc7
3 changed files with 32 additions and 3 deletions

@ -1,3 +1,9 @@
2016-03-07 Peter Stephenson <p.stephenson@samsung.com>
* 38094: Src/signals.c, Test/C03traps.ztst: POSIX exit traps
aren't local so local level should be 0 so they don't
get trashed if defined in a function.
2016-03-06 Barton E. Schaefer <schaefer@zsh.org>
* 38106: Src/parse.c: if...then if...else should be a parse error.

@ -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;
}

@ -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