Source-Changes-HG archive

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

[src/trunk]: src/bin/sh PR bin/42184 PR bin/52687 (detailing the same bug).



details:   https://anonhg.NetBSD.org/src/rev/22b773af2923
branches:  trunk
changeset: 365423:22b773af2923
user:      kre <kre%NetBSD.org@localhost>
date:      Tue Aug 14 13:36:42 2018 +0000

description:
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 c3c10667d63b -r 22b773af2923 bin/sh/eval.c
--- a/bin/sh/eval.c     Tue Aug 14 13:21:52 2018 +0000
+++ b/bin/sh/eval.c     Tue Aug 14 13:36:42 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: eval.c,v 1.156 2018/07/25 14:42:50 kre Exp $   */
+/*     $NetBSD: eval.c,v 1.157 2018/08/14 13:36:42 kre 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.156 2018/07/25 14:42:50 kre Exp $");
+__RCSID("$NetBSD: eval.c,v 1.157 2018/08/14 13:36:42 kre Exp $");
 #endif
 #endif /* not lint */
 
@@ -904,7 +904,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
@@ -918,11 +918,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 ||
@@ -948,9 +957,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