From owner-freebsd-bugs@FreeBSD.ORG Tue Sep 8 21:10:06 2009 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 785DC1065692 for ; Tue, 8 Sep 2009 21:10:06 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 682628FC30 for ; Tue, 8 Sep 2009 21:10:06 +0000 (UTC) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.14.3/8.14.3) with ESMTP id n88LA2Tu017102 for ; Tue, 8 Sep 2009 21:10:02 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.3/8.14.3/Submit) id n88LA2aa017101; Tue, 8 Sep 2009 21:10:02 GMT (envelope-from gnats) Date: Tue, 8 Sep 2009 21:10:02 GMT Message-Id: <200909082110.n88LA2aa017101@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org From: Jilles Tjoelker Cc: Subject: Re: bin/137659: sh(1): /bin/sh fails to redirect stderr in backticks X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Jilles Tjoelker List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 08 Sep 2009 21:10:06 -0000 The following reply was made to PR bin/137659; it has been noted by GNATS. From: Jilles Tjoelker To: bug-followup@FreeBSD.org, yar@freebsd.org Cc: Subject: Re: bin/137659: sh(1): /bin/sh fails to redirect stderr in backticks Date: Tue, 8 Sep 2009 23:02:35 +0200 --G4iJoqBmSsgzjUCe Content-Type: text/plain; charset=us-ascii Content-Disposition: inline There are indeed bugs with stderr output from builtins in backticks, but this is not one of them. Your bug also occurs outside backticks. $ nosuchtool 2>/dev/null nosuchtool: not found $ /nosuchtool 2>/dev/null $ (nosuchtool) 2>/dev/null The following patch fixes this, effectively by making the nosuchtool case like the /nosuchtool case (this involves forking while it is known that the command does not exist, but simplifies the code). There is a similar issue with the 'builtin' command but this is intertwined with some other stderr changes, so it will wait. -- Jilles Tjoelker --G4iJoqBmSsgzjUCe Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="unknowncmd-fd2.patch" Index: bin/sh/exec.c =================================================================== --- bin/sh/exec.c (revision 196885) +++ bin/sh/exec.c (working copy) @@ -429,6 +429,7 @@ outfmt(out2, "%s: %s\n", name, strerror(e)); } entry->cmdtype = CMDUNKNOWN; + entry->u.index = 0; return; success: Index: bin/sh/eval.c =================================================================== --- bin/sh/eval.c (revision 196885) +++ bin/sh/eval.c (working copy) @@ -713,12 +713,7 @@ 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 @@ /* 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 Index: tools/regression/bin/sh/execution/unknown1.0 =================================================================== --- tools/regression/bin/sh/execution/unknown1.0 (revision 0) +++ tools/regression/bin/sh/execution/unknown1.0 (revision 0) @@ -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 Property changes on: tools/regression/bin/sh/execution/unknown1.0 ___________________________________________________________________ Added: svn:keywords + FreeBSD=%H --G4iJoqBmSsgzjUCe--