From 8c37e6f077b3e0ad19ade309739f17d4b534572c Mon Sep 17 00:00:00 2001 From: Bart Schaefer Date: Thu, 1 Mar 2012 03:33:18 +0000 Subject: 30272 (tweaked): most failures of fork() cause non-interactive shells to exit nonzero; bad options to "exec" cause exit under POSIX_BUILTINS. --- Src/exec.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'Src') diff --git a/Src/exec.c b/Src/exec.c index 503e0843d..aa5c1000e 100644 --- a/Src/exec.c +++ b/Src/exec.c @@ -1617,9 +1617,8 @@ execpline(Estate state, wordcode slcode, int how, int last1) (list_pipe || (pline_level && !(jn->stat & STAT_SUBJOB))))) deletejob(jn, 0); thisjob = pj; - } - if (slflags & WC_SUBLIST_NOT) + if ((slflags & WC_SUBLIST_NOT) && !errflag) lastval = !lastval; } if (!pline_level) @@ -1679,9 +1678,13 @@ execpline2(Estate state, wordcode pcode, if (pipe(synch) < 0) { zerr("pipe failed: %e", errno); + lastval = errflag = 1; + return; } else if ((pid = zfork(&bgtime)) == -1) { close(synch[0]); close(synch[1]); + lastval = errflag = 1; + return; } else if (pid) { char dummy, *text; @@ -2490,7 +2493,7 @@ execcmd(Estate state, int input, int output, int how, int last1) if (!firstnode(args)) { zerr("exec requires a command to execute"); errflag = lastval = 1; - return; + goto done; } uremnode(args, firstnode(args)); if (!strcmp(next, "--")) @@ -2507,12 +2510,12 @@ execcmd(Estate state, int input, int output, int how, int last1) if (!firstnode(args)) { zerr("exec requires a command to execute"); errflag = lastval = 1; - return; + goto done; } if (!nextnode(firstnode(args))) { zerr("exec flag -a requires a parameter"); errflag = lastval = 1; - return; + goto done; } exec_argv0 = (char *) getdata(nextnode(firstnode(args))); @@ -2813,15 +2816,12 @@ execcmd(Estate state, int input, int output, int how, int last1) if (pipe(synch) < 0) { zerr("pipe failed: %e", errno); - if (oautocont >= 0) - opts[AUTOCONTINUE] = oautocont; - return; + goto fatal; } else if ((pid = zfork(&bgtime)) == -1) { close(synch[0]); close(synch[1]); - if (oautocont >= 0) - opts[AUTOCONTINUE] = oautocont; - return; + lastval = errflag = 1; + goto fatal; } if (pid) { @@ -3365,6 +3365,7 @@ execcmd(Estate state, int input, int output, int how, int last1) * classify as a builtin) we treat all errors as fatal. * The "command" builtin is not special so resets this behaviour. */ + fatal: if (redir_err || errflag) { if (!isset(INTERACTIVE)) { if (forked) -- cgit 1.4.1