From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11917 invoked by alias); 20 Feb 2011 20:17:56 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 28784 Received: (qmail 1267 invoked from network); 20 Feb 2011 20:17:53 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received-SPF: pass (ns1.primenet.com.au: SPF record at ntlworld.com designates 81.103.221.47 as permitted sender) Date: Sun, 20 Feb 2011 20:17:23 +0000 From: Peter Stephenson To: "Zsh Hackers' List" Subject: Re: sh compatibility issue Message-ID: <20110220201723.0b8b7a1a@pws-pc.ntlworld.com> In-Reply-To: <20110220191159.12627718@pws-pc.ntlworld.com> References: <20110218103012.27fd1869@pwslap01u.europe.root.pri> <20110219230540.GA81416@stack.nl> <20110220191159.12627718@pws-pc.ntlworld.com> X-Mailer: Claws Mail 3.7.8 (GTK+ 2.22.0; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Cloudmark-Analysis: v=1.1 cv=R50lirqlHffDPPkwUlkuVa99MrvKdVWo//yz83qex8g= c=1 sm=0 a=kj9zAlcOel0A:10 a=NLZqzBF-AAAA:8 a=OD2QaEM_-0K8s-7zX5AA:9 a=qpUrA7Ys3DBo9C0p-GoA:7 a=Z2p823NBYacmVWZ3OfPRkYGALJcA:4 a=CjuIK1q_8ugA:10 a=_dQi-Dcv4p4A:10 a=BkDEZNLB87yQKGav:21 a=1GFOiclLPcofDuaX:21 a=HpAAvcLHHh0Zw7uRqdWCyQ==:117 On Sun, 20 Feb 2011 19:11:59 +0000 Peter Stephenson wrote: > On Sun, 20 Feb 2011 00:05:40 +0100 > Jilles Tjoelker wrote: > > On a related note, here is another quite insidious sh compatibility > > issue: > > sh -c 'exec > This should not print "wrong" because exec is a special builtin and > > redirection errors on special builtins are fatal. Most shells get this > > right nowadays (bash only in POSIX mode) but zsh gets it wrong. Even > > set -o posixbuiltins > > does not help. > > I think it does need to be fatal, but not because it's a special builtin > --- it looks like that's only a "may" rather than a "shall" --- but > because there is a rule for exec: > > If a redirection error occurs (see Consequences of Shell Errors ), the > shell shall exit with a value in the range 1-125 > > which is certainly unambiguous on the subject. This will need looking at. I think this is unproblematic. The relevant hooks are already mostly there. Index: Doc/Zsh/options.yo =================================================================== RCS file: /cvsroot/zsh/zsh/Doc/Zsh/options.yo,v retrieving revision 1.99 diff -p -u -r1.99 options.yo --- Doc/Zsh/options.yo 16 Dec 2010 13:55:35 -0000 1.99 +++ Doc/Zsh/options.yo 20 Feb 2011 20:11:45 -0000 @@ -1866,6 +1870,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) Index: Test/A04redirect.ztst =================================================================== RCS file: /cvsroot/zsh/zsh/Test/A04redirect.ztst,v retrieving revision 1.15 diff -p -u -r1.15 A04redirect.ztst --- Test/A04redirect.ztst 14 Sep 2010 14:46:26 -0000 1.15 +++ Test/A04redirect.ztst 20 Feb 2011 20:11:45 -0000 @@ -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 Index: Src/exec.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/exec.c,v retrieving revision 1.188 diff -p -u -r1.188 exec.c --- Src/exec.c 17 Feb 2011 19:52:42 -0000 1.188 +++ Src/exec.c 20 Feb 2011 20:11:46 -0000 @@ -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 out 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 out 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); -- Peter Stephenson Web page now at http://homepage.ntlworld.com/p.w.stephenson/