NetBSD Problem Report #52687

From www@NetBSD.org  Wed Nov  1 12:01:42 2017
Return-Path: <www@NetBSD.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id B35567A1E7
	for <gnats-bugs@gnats.NetBSD.org>; Wed,  1 Nov 2017 12:01:42 +0000 (UTC)
Message-Id: <20171101120141.C04177A210@mollari.NetBSD.org>
Date: Wed,  1 Nov 2017 12:01:41 +0000 (UTC)
From: coypu@sdf.org
Reply-To: coypu@sdf.org
To: gnats-bugs@NetBSD.org
Subject: can't suppress warnings from /bin/sh
X-Send-Pr-Version: www-1.0

>Number:         52687
>Category:       bin
>Synopsis:       can't suppress warnings from /bin/sh
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    kre
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Nov 01 12:05:00 +0000 2017
>Closed-Date:    Sat Aug 25 11:50:12 +0000 2018
>Last-Modified:  Sat Aug 25 11:50:12 +0000 2018
>Originator:     coypu
>Release:        NetBSD 8.99.4
>Organization:
>Environment:
NetBSD localhost 8.99.4 NetBSD 8.99.4 (GENERIC) #3: Sun Oct 22 03:14:21 IDT 2017  fly@localhost:/home/fly/obj/sys/arch/amd64/compile/GENERIC amd64

>Description:
$ nonexistent 2>/dev/null
nonexistent: not found

Would like to receive no output.
>How-To-Repeat:

>Fix:

>Release-Note:

>Audit-Trail:
From: coypu@sdf.org
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: bin/52687: can't suppress warnings from /bin/sh
Date: Wed, 1 Nov 2017 12:11:32 +0000

 I was hinted at this, which works:
 (nonexistent) 2>/dev/null

 And I am redirecting nonexistent's stderr.

From: christos@zoulas.com (Christos Zoulas)
To: gnats-bugs@NetBSD.org, gnats-admin@netbsd.org, netbsd-bugs@netbsd.org, 
	coypu@sdf.org
Cc: 
Subject: Re: bin/52687: can't suppress warnings from /bin/sh
Date: Wed, 1 Nov 2017 09:02:50 -0400

 On Nov 1, 12:15pm, coypu@sdf.org (coypu@sdf.org) wrote:
 -- Subject: Re: bin/52687: can't suppress warnings from /bin/sh

 |  I was hinted at this, which works:
 |  (nonexistent) 2>/dev/null
 |  
 |  And I am redirecting nonexistent's stderr.

 This is by design; 

     nonexistent 2> /dev/null

 Means redirect file descriptor 2 of the child process.  The shell
 tries to execute the child process (after redirection is done),
 fails and prints the error message. You need to redirect fd 2 of
 the shell. To do this you either need to capture fd 2 of another
 shell (the subshell solution above) or:

     $ exec 3>&2 2> /dev/null
     nonexistent
     exec 2>&3
     $

 christos

Responsible-Changed-From-To: bin-bug-people->kre
Responsible-Changed-By: kre@NetBSD.org
Responsible-Changed-When: Wed, 01 Nov 2017 13:16:19 +0000
Responsible-Changed-Why:
Mine.


From: Robert Elz <kre@munnari.OZ.AU>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: bin/52687: can't suppress warnings from /bin/sh
Date: Wed, 01 Nov 2017 20:48:07 +0700

     Date:        Wed,  1 Nov 2017 13:05:01 +0000 (UTC)
     From:        christos@zoulas.com (Christos Zoulas)
     Message-ID:  <20171101130501.21C1C7A212@mollari.NetBSD.org>

   |  This is by design; 
   |  
   |      nonexistent 2> /dev/null
   |  
   |  Means redirect file descriptor 2 of the child process.

 That may be, but the NetBSD sh is about the only one (well, is the only one
 I can find) that behaves this way.

 I am not sure that being different, just for the sake of it, is really
 a good idea.

 And with ...

   |      $ exec 3>&2 2> /dev/null
   |      nonexistent
   |      exec 2>&3

 You'd also want (probably) 3>&- at the end of that last line.

 kre

From: Robert Elz <kre@munnari.OZ.AU>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: bin/52687: can't suppress warnings from /bin/sh
Date: Wed, 01 Nov 2017 21:32:41 +0700

     Date:        Wed,  1 Nov 2017 12:15:01 +0000 (UTC)
     From:        coypu@sdf.org
     Message-ID:  <20171101121501.7AC3D7A210@mollari.NetBSD.org>

   |  I was hinted at this, which works:
   |  (nonexistent) 2>/dev/null

 It does, but unless you need a sub-shell, which nothing in
 the original suggested

 	{ nonexistant; } 2>/dev/null

 works as well, without an extra fork.

 It is still likely that, unless people really want to keep the
 current behaviour, that I will change sh to be like every other
 shell (I can find) on the planet (including FreeBSD's).

 kre

From: Robert Elz <kre@munnari.OZ.AU>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: bin/52687: can't suppress warnings from /bin/sh
Date: Wed, 01 Nov 2017 21:36:03 +0700

 And in support of changing it ...

 	andromeda$ sh -c '/non/exist 2>/dev/null'
 	andromeda$ 

 is needlessly different from

 	andromeda$ sh -c 'nonexist 2>/dev/null'
 	nonexist: not found
 	andromeda$

 for no particularly good reason (other than the way it happens to
 be implemented.)

 kre

From: Robert Elz <kre@munnari.OZ.AU>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: bin/52687: can't suppress warnings from /bin/sh
Date: Wed, 01 Nov 2017 22:22:08 +0700

     Date:        Wed,  1 Nov 2017 14:35:01 +0000 (UTC)
     From:        Robert Elz <kre@munnari.OZ.AU>
     Message-ID:  <20171101143501.7CC097A1E9@mollari.NetBSD.org>

 And just for completeness (And not about the redirect)...

   |  	{ nonexistant; } 2>/dev/null
   |  
   |  works as well, without an extra fork.

 it is worth pointing out that POSIX allows a non-interactive shell
 to exit if an attempt is made to run a command that cannot be found.

 I'm not aware of any (modern) shell that makes use of that permission.
 all seem to continue after writing the error (and returning a 127 status)
 but it is worth noting that if you are deliberately running commands that
 might not exist, in a script, that doing it in a sub-shell is the portable
 way (then the shell that exits, if any does, is the sub-shell.)

 kre

From: "Robert Elz" <kre@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/52687 CVS commit: src/bin/sh
Date: Tue, 14 Aug 2018 13:36:42 +0000

 Module Name:	src
 Committed By:	kre
 Date:		Tue Aug 14 13:36:42 UTC 2018

 Modified Files:
 	src/bin/sh: eval.c

 Log Message:
 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


 To generate a diff of this commit:
 cvs rdiff -u -r1.156 -r1.157 src/bin/sh/eval.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: open->feedback
State-Changed-By: kre@NetBSD.org
State-Changed-When: Tue, 14 Aug 2018 13:48:54 +0000
State-Changed-Why:
A fix for this has just been committed to
NetBSD HEAD.  If you could test and confirm that it behaves correctly, it would be appreciated


From: coypu@sdf.org
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: bin/52687 (can't suppress warnings from /bin/sh)
Date: Thu, 16 Aug 2018 13:35:31 +0000

 It works well, thanks!
 (I can't guarantee all cases of shell redirection do, but my case does)

State-Changed-From-To: feedback->pending-pullups
State-Changed-By: kre@NetBSD.org
State-Changed-When: Thu, 16 Aug 2018 15:51:22 +0000
State-Changed-Why:
Confirmed working, thanks, now needs pullup to -8
(after a little more time to allow more use in case something
untoward happens).


State-Changed-From-To: pending-pullups->needs-pullups
State-Changed-By: kre@NetBSD.org
State-Changed-When: Thu, 16 Aug 2018 15:52:22 +0000
State-Changed-Why:
Oops, meant needs-pullups, not pending...


State-Changed-From-To: needs-pullups->pending-pullups
State-Changed-By: kre@NetBSD.org
State-Changed-When: Mon, 20 Aug 2018 13:13:35 +0000
State-Changed-Why:
pullup-8 #982


From: "Martin Husemann" <martin@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/52687 CVS commit: [netbsd-8] src/bin/sh
Date: Sat, 25 Aug 2018 11:45:41 +0000

 Module Name:	src
 Committed By:	martin
 Date:		Sat Aug 25 11:45:40 UTC 2018

 Modified Files:
 	src/bin/sh [netbsd-8]: eval.c

 Log Message:
 Pull up following revision(s) (requested by kre in ticket #982):

 	bin/sh/eval.c: revision 1.157

 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


 To generate a diff of this commit:
 cvs rdiff -u -r1.140.2.3 -r1.140.2.4 src/bin/sh/eval.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: pending-pullups->closed
State-Changed-By: kre@NetBSD.org
State-Changed-When: Sat, 25 Aug 2018 11:50:12 +0000
State-Changed-Why:
Pullups completed


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.43 2018/01/16 07:36:43 maya Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2017 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.