Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/netbsd-8]: src/bin/sh Pull up following revision(s) (requested by kre in...



details:   https://anonhg.NetBSD.org/src/rev/b44f3f885977
branches:  netbsd-8
changeset: 435206:b44f3f885977
user:      martin <martin%NetBSD.org@localhost>
date:      Sat Aug 25 11:45:40 2018 +0000

description:
Pull up following revision(s) (requested by kre in ticket #982):

        bin/sh/eval.c: revision 1.157

PR bin/42184 PR bin/52687  (detailing the same bug).

Fix "command not found" handling so that the error message
goes to stderr (after any redirections are applied).

More importantly, in

        foo > /tmp/junk

/tmp/junk should be created, before any attempt is made
to execute (the assumed non-existing) "foo".

All this was always true for any command (not found command)
containing a / in its name

        foo/bar >/tmp/junk  2>>/tmp/errs

would have created /tmp/junk, then complained (in /tmp/errs)
about foo/bar not being found.   Now that happens for ordinary
commands as well.

The fix (which I found when I saw differences between our
code and FreeBSD's, where, for the benefit of PR 42184,
this has been fixed, sometime in the past 9 years) is
frighteningly simple.   Simply do not short circuit execution
(or print any error) when the initial lookup fails to
find the command - it will fail anyway when we actually
try running it.   The cost is a (seemingly unnecessary,
except that it really is) fork in this case.

This is what I had been planning, but I expected it would
be much more difficult than it turned out....

XXX pullup-8

diffstat:

 bin/sh/eval.c |  22 ++++++++++++++++------
 1 files changed, 16 insertions(+), 6 deletions(-)

diffs (62 lines):

diff -r 8b573e093b28 -r b44f3f885977 bin/sh/eval.c
--- a/bin/sh/eval.c     Sat Aug 25 11:38:19 2018 +0000
+++ b/bin/sh/eval.c     Sat Aug 25 11:45:40 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: eval.c,v 1.140.2.3 2018/07/13 14:29:15 martin Exp $    */
+/*     $NetBSD: eval.c,v 1.140.2.4 2018/08/25 11:45:40 martin Exp $    */
 
 /*-
  * Copyright (c) 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)eval.c     8.9 (Berkeley) 6/8/95";
 #else
-__RCSID("$NetBSD: eval.c,v 1.140.2.3 2018/07/13 14:29:15 martin Exp $");
+__RCSID("$NetBSD: eval.c,v 1.140.2.4 2018/08/25 11:45:40 martin Exp $");
 #endif
 #endif /* not lint */
 
@@ -903,7 +903,7 @@
                cmdentry.u.bltin = bltincmd;
        } else {
                static const char PATH[] = "PATH=";
-               int cmd_flags = DO_ERR;
+               int cmd_flags = 0;
 
                /*
                 * Modify the command lookup path, if a PATH= assignment
@@ -917,11 +917,20 @@
                        int argsused, use_syspath;
 
                        find_command(argv[0], &cmdentry, cmd_flags, path);
+#if 0
+                       /*
+                        * This short circuits all of the processing that
+                        * should be done (including processing the
+                        * redirects), so just don't ...
+                        *
+                        * (eventually this whole #if'd block will vanish)
+                        */
                        if (cmdentry.cmdtype == CMDUNKNOWN) {
                                exitstatus = 127;
                                flushout(&errout);
                                goto out;
                        }
+#endif
 
                        /* implement the 'command' builtin here */
                        if (cmdentry.cmdtype != CMDBUILTIN ||
@@ -947,9 +956,10 @@
 
        /* Fork off a child process if necessary. */
        if (cmd->ncmd.backgnd || (trap[0] && (flags & EV_EXIT) != 0)
-        || (cmdentry.cmdtype == CMDNORMAL && (flags & EV_EXIT) == 0)
-        || ((flags & EV_BACKCMD) != 0
-           && ((cmdentry.cmdtype != CMDBUILTIN && cmdentry.cmdtype != CMDSPLBLTIN)
+        || ((cmdentry.cmdtype == CMDNORMAL || cmdentry.cmdtype == CMDUNKNOWN)
+            && (flags & EV_EXIT) == 0)
+        || ((flags & EV_BACKCMD) != 0 &&
+           ((cmdentry.cmdtype != CMDBUILTIN && cmdentry.cmdtype != CMDSPLBLTIN)
                 || cmdentry.u.bltin == dotcmd
                 || cmdentry.u.bltin == evalcmd))) {
                INTOFF;



Home | Main Index | Thread Index | Old Index