Author: jilles
Date: Tue Oct  6 22:00:14 2009
New Revision: 197820
URL: http://svn.freebsd.org/changeset/base/197820

Log:
  sh: Send the "xyz: not found" message to redirected fd 2.
  This also fixes that trying to execute a non-regular file with a command
  name without '/' returns 127 instead of 126.
  The fix is rather simplistic: treat CMDUNKNOWN as if the command were found
  as an external program. The resulting fork is a bit wasteful but executing
  unknown commands should not be very frequent.
  
  PR:           bin/137659

Added:
  head/tools/regression/bin/sh/execution/unknown1.0   (contents, props changed)
Modified:
  head/bin/sh/eval.c
  head/bin/sh/exec.c

Modified: head/bin/sh/eval.c
==============================================================================
--- head/bin/sh/eval.c  Tue Oct  6 21:49:13 2009        (r197819)
+++ head/bin/sh/eval.c  Tue Oct  6 22:00:14 2009        (r197820)
@@ -713,12 +713,7 @@ evalcommand(union node *cmd, int flags, 
                                do_clearcmdentry = 1;
                        }
 
-               find_command(argv[0], &cmdentry, 1, path);
-               if (cmdentry.cmdtype == CMDUNKNOWN) {   /* command not found */
-                       exitstatus = 127;
-                       flushout(&errout);
-                       return;
-               }
+               find_command(argv[0], &cmdentry, 0, path);
                /* implement the bltin builtin here */
                if (cmdentry.cmdtype == CMDBUILTIN && cmdentry.u.index == 
BLTINCMD) {
                        for (;;) {
@@ -740,7 +735,7 @@ evalcommand(union node *cmd, int flags, 
 
        /* Fork off a child process if necessary. */
        if (cmd->ncmd.backgnd
-        || (cmdentry.cmdtype == CMDNORMAL
+        || ((cmdentry.cmdtype == CMDNORMAL || cmdentry.cmdtype == CMDUNKNOWN)
            && ((flags & EV_EXIT) == 0 || have_traps()))
         || ((flags & EV_BACKCMD) != 0
            && (cmdentry.cmdtype != CMDBUILTIN

Modified: head/bin/sh/exec.c
==============================================================================
--- head/bin/sh/exec.c  Tue Oct  6 21:49:13 2009        (r197819)
+++ head/bin/sh/exec.c  Tue Oct  6 22:00:14 2009        (r197820)
@@ -429,6 +429,7 @@ loop:
                        outfmt(out2, "%s: %s\n", name, strerror(e));
        }
        entry->cmdtype = CMDUNKNOWN;
+       entry->u.index = 0;
        return;
 
 success:

Added: head/tools/regression/bin/sh/execution/unknown1.0
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ head/tools/regression/bin/sh/execution/unknown1.0   Tue Oct  6 22:00:14 
2009        (r197820)
@@ -0,0 +1,29 @@
+# $FreeBSD$
+
+nosuchtool 2>/dev/null
+[ $? -ne 127 ] && exit 1
+/var/empty/nosuchtool 2>/dev/null
+[ $? -ne 127 ] && exit 1
+(nosuchtool) 2>/dev/null
+[ $? -ne 127 ] && exit 1
+(/var/empty/nosuchtool) 2>/dev/null
+[ $? -ne 127 ] && exit 1
+/ 2>/dev/null
+[ $? -ne 126 ] && exit 1
+PATH=/usr bin 2>/dev/null
+[ $? -ne 126 ] && exit 1
+
+dummy=$(nosuchtool 2>/dev/null)
+[ $? -ne 127 ] && exit 1
+dummy=$(/var/empty/nosuchtool 2>/dev/null)
+[ $? -ne 127 ] && exit 1
+dummy=$( (nosuchtool) 2>/dev/null)
+[ $? -ne 127 ] && exit 1
+dummy=$( (/var/empty/nosuchtool) 2>/dev/null)
+[ $? -ne 127 ] && exit 1
+dummy=$(/ 2>/dev/null)
+[ $? -ne 126 ] && exit 1
+dummy=$(PATH=/usr bin 2>/dev/null)
+[ $? -ne 126 ] && exit 1
+
+exit 0
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to