From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: "Zsh Hackers' List" <zsh-workers@zsh.org>
Subject: Re: sh compatibility issue
Date: Sun, 20 Feb 2011 20:17:23 +0000 [thread overview]
Message-ID: <20110220201723.0b8b7a1a@pws-pc.ntlworld.com> (raw)
In-Reply-To: <20110220191159.12627718@pws-pc.ntlworld.com>
On Sun, 20 Feb 2011 19:11:59 +0000
Peter Stephenson <p.w.stephenson@ntlworld.com> wrote:
> On Sun, 20 Feb 2011 00:05:40 +0100
> Jilles Tjoelker <jilles@stack.nl> wrote:
> > On a related note, here is another quite insidious sh compatibility
> > issue:
> > sh -c 'exec </nonexistent/a; echo wrong'
> > 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 <p.w.stephenson@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/
next prev parent reply other threads:[~2011-02-20 20:17 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-02-18 3:55 Vincent Stemen
2011-02-18 10:30 ` Peter Stephenson
2011-02-18 22:45 ` Vincent Stemen
2011-02-19 23:05 ` Jilles Tjoelker
2011-02-20 0:41 ` Vincent Stemen
2011-02-20 19:11 ` Peter Stephenson
2011-02-20 20:17 ` Peter Stephenson [this message]
2011-02-20 21:12 ` Vincent Stemen
[not found] ` <4D618A11.3050406@case.edu>
2011-02-22 20:02 ` Peter Stephenson
2011-02-23 1:08 ` Vincent Stemen
2011-02-23 1:51 ` Bart Schaefer
2011-02-23 2:30 ` Vincent Stemen
2011-02-23 9:25 ` Peter Stephenson
2011-03-04 13:36 ` Jilles Tjoelker
2011-03-06 20:26 ` Peter Stephenson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20110220201723.0b8b7a1a@pws-pc.ntlworld.com \
--to=p.w.stephenson@ntlworld.com \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).