From owner-svn-src-head@FreeBSD.ORG Tue Oct 6 22:00:15 2009 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 93122106566B; Tue, 6 Oct 2009 22:00:15 +0000 (UTC) (envelope-from jilles@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 811CC8FC20; Tue, 6 Oct 2009 22:00:15 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n96M0FCf065305; Tue, 6 Oct 2009 22:00:15 GMT (envelope-from jilles@svn.freebsd.org) Received: (from jilles@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n96M0FMX065301; Tue, 6 Oct 2009 22:00:15 GMT (envelope-from jilles@svn.freebsd.org) Message-Id: <200910062200.n96M0FMX065301@svn.freebsd.org> From: Jilles Tjoelker Date: Tue, 6 Oct 2009 22:00:15 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r197820 - in head: bin/sh tools/regression/bin/sh/execution X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 06 Oct 2009 22:00:15 -0000 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