From dbbcbf67cb8a330e5c7d8a40ed4152a53db6b5f8 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Tue, 22 Feb 2011 20:09:20 +0000 Subject: 28791: exit on errors with special builtins with POSIXBUILTINS --- Src/exec.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'Src/exec.c') diff --git a/Src/exec.c b/Src/exec.c index da67465d8..25a2eee38 100644 --- a/Src/exec.c +++ b/Src/exec.c @@ -2416,6 +2416,8 @@ execcmd(Estate state, int input, int output, int how, int last1) checked = !(cflags & BINF_BUILTIN); break; } + cflags &= ~BINF_BUILTIN & ~BINF_COMMAND; + cflags |= hn->flags; if (!(hn->flags & BINF_PREFIX)) { is_builtin = 1; @@ -2425,8 +2427,6 @@ execcmd(Estate state, int input, int output, int how, int last1) assign = (hn->flags & BINF_MAGICEQUALS); break; } - cflags &= ~BINF_BUILTIN & ~BINF_COMMAND; - cflags |= hn->flags; checked = 0; if ((cflags & BINF_COMMAND) && nextnode(firstnode(args))) { /* check for options to command builtin */ @@ -3297,12 +3297,20 @@ execcmd(Estate state, int input, int output, int how, int last1) fixfds(save); done: - if (redir_err && isset(POSIXBUILTINS)) { - if (!isset(INTERACTIVE)) { - /* We've already _exit'ed if forked */ - exit(1); + if (isset(POSIXBUILTINS) && + (cflags & (BINF_PSPECIAL|BINF_EXEC))) { + /* + * For POSIX-compatibile behaviour with special + * builtins (including exec which we don't usually + * classify as a builtin, we treat all errors as fatal. + */ + if (redir_err || errflag) { + if (!isset(INTERACTIVE)) { + /* We've already _exit'ed if forked */ + exit(1); + } + errflag = 1; } - errflag = 1; } if (newxtrerr) { fil = fileno(newxtrerr); -- cgit 1.4.1