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

43653: explicit exit from EXIT trap overrides exit status

This commit is contained in:
Peter Stephenson 2018-10-09 10:05:05 +01:00
parent 00baf08602
commit d768a7492a
3 changed files with 18 additions and 4 deletions

@ -1,3 +1,8 @@
2018-10-09 Peter Stephenson <p.stephenson@samsung.com>
* 43653: Src/builtin.c, Test/C03traps.ztst: explicit exit from
EXIT trap overrides previous status.
2018-10-08 a-wing <1@233.email>
* 43623: Completion/Linux/Command/_iptables: Fix Completion

@ -5709,7 +5709,13 @@ int shell_exiting;
mod_export void
zexit(int val, int from_where)
{
/* Don't do anything recursively: see below */
static int exit_val;
/*
* Don't do anything recursively: see below.
* Do, however, update exit status --- there's no nesting,
* a later value always overrides an earlier.
*/
exit_val = val;
if (shell_exiting == -1)
return;
@ -5757,7 +5763,7 @@ zexit(int val, int from_where)
#endif
}
}
lastval = val;
lastval = exit_val;
/*
* Now we are committed to exiting any previous state
* is irrelevant. Ensure trap can run.
@ -5771,9 +5777,9 @@ zexit(int val, int from_where)
release_pgrp();
}
if (mypid != getpid())
_exit(val);
_exit(exit_val);
else
exit(val);
exit(exit_val);
}
/* . (dot), source */

@ -863,6 +863,9 @@ F:Must be tested with a top-level script rather than source or function
>a
>b
$ZTST_testdir/../Src/zsh -fc 'fn() { exit 13; }; trap fn EXIT; exit'
13:Explicit exit in exit trap overrides status
%clean
rm -f TRAPEXIT