users/23531: Error exit/return fixes.

Fix regression with trap on left hand side of pipe.

Fix forced return from shell structure within nested function.

Fix tests exiting too early.

Add new test case.
This commit is contained in:
Peter Stephenson 2018-07-09 11:06:07 +01:00
parent 8cb4fc00c2
commit 17178db1a4
3 changed files with 41 additions and 0 deletions

View File

@ -1,3 +1,10 @@
2018-07-09 Peter Stephenson <p.stephenson@samsung.com>
* users/23531: Src/exec.c, Test/C03traps.ztst: Fix error
exit/return from within shell construct inside nested function,
and in left hand side of pipe (regression due to broken tests);
stop tests from exiting too early and add new test for first fix.
2018-07-07 Matthew Martin <phy1729@gmail.com>
* 43106: Completion/BSD/Command/_ldap: Add ldap completer.

View File

@ -2728,6 +2728,11 @@ execcmd_fork(Estate state, int how, int type, Wordcode varspc,
if (sigtrapped[SIGINT] & ZSIG_IGNORED)
holdintr();
/*
* EXIT traps shouldn't be called even if we forked to run
* shell code as this isn't the main shell.
*/
sigtrapped[SIGEXIT] = 0;
#ifdef HAVE_NICE
/* Check if we should run background jobs at a lower priority. */
if ((how & Z_ASYNC) && isset(BGNICE))
@ -5792,7 +5797,19 @@ doshfunc(Shfunc shfunc, LinkList doshargs, int noreturnval)
undoshfunc:
--funcdepth;
if (retflag) {
/*
* This function is forced to return.
*/
retflag = 0;
/*
* The calling function isn't necessarily forced to return,
* but it should be made sensitive to ERR_EXIT and
* ERR_RETURN as the assumptions we made at the end of
* constructs within this function no longer apply. If
* there are cases where this is not true, they need adding
* to C03traps.ztst.
*/
this_noerrexit = 0;
breaks = funcsave->breaks;
}
freearray(pparams);

View File

@ -680,6 +680,22 @@ F:Must be tested with a top-level script rather than source or function
>Better
>In .zshenv
unsetopt errreturn
fn2() {
if true; then
false
fi
}
fn1() {
setopt localoptions errreturn
fn2
print $?
}
fn1
print fn1 done
0:ERR_RETURN caused by function returning false from within shell construct
>fn1 done
fn2() {
if false; then
print Bad
@ -741,6 +757,7 @@ F:Must be tested with a top-level script rather than source or function
0:ERR_EXIT not triggered by status 1 at end of { }
>OK
unsetopt err_exit err_return
(setopt err_exit
for x in y; do
false