Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 8 Sep 2009 21:10:02 GMT
From:      Jilles Tjoelker <jilles@stack.nl>
To:        freebsd-bugs@FreeBSD.org
Subject:   Re: bin/137659: sh(1): /bin/sh fails to redirect stderr in backticks
Message-ID:  <200909082110.n88LA2aa017101@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help
The following reply was made to PR bin/137659; it has been noted by GNATS.

From: Jilles Tjoelker <jilles@stack.nl>
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--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200909082110.n88LA2aa017101>