diff options
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | Doc/Zsh/options.yo | 4 | ||||
-rw-r--r-- | Src/exec.c | 19 | ||||
-rw-r--r-- | Test/A04redirect.ztst | 12 |
4 files changed, 39 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog index b5e23d523..c0fb29e8b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-02-21 Peter Stephenson <pws@csr.com> + + * 28784: Doc/Zsh/options.yo, Test/A04redirect.ztst, Src/exec.c: + exit on exec redirection error with POSIXBUILTINS. + 2011-02-19 Frank Terbeck <ft@bewatermyfriend.org> * 28776: Functions/VCS_Info/VCS_INFO_bydir_detect, @@ -14233,5 +14238,5 @@ ***************************************************** * This is used by the shell to define $ZSH_PATCHLEVEL -* $Revision: 1.5203 $ +* $Revision: 1.5204 $ ***************************************************** diff --git a/Doc/Zsh/options.yo b/Doc/Zsh/options.yo index a96597157..842e5c27b 100644 --- a/Doc/Zsh/options.yo +++ b/Doc/Zsh/options.yo @@ -1866,6 +1866,10 @@ tt(source), tt(times), tt(trap) and tt(unset). + +In addition, a failed redirection after tt(exec) causes a non-interactive +shell to exit and an interactive shell to return to its top-level +processing. ) pindex(POSIX_IDENTIFIERS) pindex(NO_POSIX_IDENTIFIERS) diff --git a/Src/exec.c b/Src/exec.c index 11d37f1b3..da67465d8 100644 --- a/Src/exec.c +++ b/Src/exec.c @@ -181,7 +181,15 @@ struct execstack *exstack; /**/ mod_export Funcstack funcstack; -#define execerr() if (!forked) { lastval = 1; goto done; } else _exit(1) +#define execerr() \ + do { \ + if (!forked) { \ + redir_err = lastval = 1; \ + goto done; \ + } else { \ + _exit(1); \ + } \ + } while (0) static int doneps4; static char *STTYval; @@ -2312,7 +2320,7 @@ execcmd(Estate state, int input, int output, int how, int last1) struct multio *mfds[10]; char *text; int save[10]; - int fil, dfil, is_cursh, type, do_exec = 0, i, htok = 0; + int fil, dfil, is_cursh, type, do_exec = 0, redir_err = 0, i, htok = 0; int nullexec = 0, assign = 0, forked = 0; int is_shfunc = 0, is_builtin = 0, is_exec = 0, use_defpath = 0; /* Various flags to the command. */ @@ -3289,6 +3297,13 @@ 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); + } + errflag = 1; + } if (newxtrerr) { fil = fileno(newxtrerr); fclose(newxtrerr); diff --git a/Test/A04redirect.ztst b/Test/A04redirect.ztst index 1c63b6377..c35977c66 100644 --- a/Test/A04redirect.ztst +++ b/Test/A04redirect.ztst @@ -366,3 +366,15 @@ >more output: >This file contains data. >This file contains data. + + $ZTST_testdir/../Src/zsh -fc 'exec >/nonexistent/nonexistent + echo output' +0:failed exec redir, no POSIX_BUILTINS +>output +?zsh:1: no such file or directory: /nonexistent/nonexistent + + $ZTST_testdir/../Src/zsh -f -o POSIX_BUILTINS -c ' + exec >/nonexistent/nonexistent + echo output' +1:failed exec redir, POSIX_BUILTINS +?zsh:2: no such file or directory: /nonexistent/nonexistent |