NetBSD Problem Report #42184
From cheusov@tut.by Wed Oct 14 18:17:32 2009
Return-Path: <cheusov@tut.by>
Received: from mail.netbsd.org (mail.netbsd.org [204.152.190.11])
by www.NetBSD.org (Postfix) with ESMTP id 7DEF063C32C
for <gnats-bugs@gnats.netbsd.org>; Wed, 14 Oct 2009 18:17:32 +0000 (UTC)
Message-Id: <s93d44pu9m0.fsf@chen.chizhovka.net>
Date: Wed, 14 Oct 2009 21:13:43 +0300
From: cheusov@tut.by
To: gnats-bugs@gnats.NetBSD.org
Subject: /bin/sh: stderr vs. command not found
X-Send-Pr-Version: 3.95
>Number: 42184
>Category: bin
>Synopsis: /bin/sh: stderr vs. command not found
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: bin-bug-people
>State: closed
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Wed Oct 14 18:20:00 +0000 2009
>Closed-Date: Sat Dec 29 09:53:12 +0000 2018
>Last-Modified: Sat Dec 29 09:53:12 +0000 2018
>Originator: Aleksey Cheusov
>Release: NetBSD 5.0_STABLE
>Organization:
>Environment:
System: NetBSD chen.chizhovka.net 5.0_STABLE NetBSD 5.0_STABLE (GENERIC) #0: Sat Sep 12 14:12:09 EEST 2009 cheusov@chen.chizhovka.net:/srv/obj/sys/arch/i386/compile/GENERIC i386
Architecture: i386
Machine: i386
>Description:
/bin/sh doesn't print "xxx: not found" to stderr
in case xxx cannot be found.
1 ~>cat /home/cheusov/tmp/1.sh
#!/bin/sh
bad_command_name 2>/dev/null
0 ~>/bin/sh /home/cheusov/tmp/1.sh
bad_command_name: not found
127 ~>bash /home/cheusov/tmp/1.sh
127 ~>zsh /home/cheusov/tmp/1.sh
127 ~>ksh /home/cheusov/tmp/1.sh
127 ~>dash /home/cheusov/tmp/1.sh
127 ~>pdksh /home/cheusov/tmp/1.sh
127 ~>/usr/pkg/heirloom/bin/sh /home/cheusov/tmp/1.sh
/home/cheusov/tmp/1.sh: bad_command_name: not found
1 ~>
I assume this is a bug because
a) wrapping of bad command envocation into
a shell function solves the problrem.
0 ~>cat /home/cheusov/tmp/1.sh
#!/bin/sh
wrapper (){
bad_command_name
}
wrapper 2>/dev/null
0 ~>/bin/sh /home/cheusov/tmp/1.sh
127 ~>bash /home/cheusov/tmp/1.sh
127 ~>zsh /home/cheusov/tmp/1.sh
127 ~>dash /home/cheusov/tmp/1.sh
127 ~>pdksh /home/cheusov/tmp/1.sh
127 ~>/usr/pkg/heirloom/bin/sh /home/cheusov/tmp/1.sh
1 ~>
b) most other shells works as expected.
FreeBSD /bin/sh (ash derivate too) is also broken here.
>How-To-Repeat:
>Fix:
Unknown
>Release-Note:
>Audit-Trail:
From: David Laight <david@l8s.co.uk>
To: gnats-bugs@NetBSD.org
Cc:
Subject: Re: bin/42184: /bin/sh: stderr vs. command not found
Date: Wed, 14 Oct 2009 20:17:26 +0100
On Wed, Oct 14, 2009 at 06:20:00PM +0000, cheusov@tut.by wrote:
> >Number: 42184
> >Synopsis: /bin/sh: stderr vs. command not found
...
> /bin/sh doesn't print "xxx: not found" to stderr
> in case xxx cannot be found.
>
> 1 ~>cat /home/cheusov/tmp/1.sh
> #!/bin/sh
>
> bad_command_name 2>/dev/null
Actually, it does print the error message to stderr.
It does so in its own context, not that the command would run in.
So the redirect on the line itself has no effect.
The TOG spec:
http://www.opengroup.org/onlinepubs/000095399/utilities/xcu_chap02.html
does seem to imply that redirection be done before command lookup!
However this is all hard! The 'command environment' doesn't exist
until later ...
David
--
David Laight: david@l8s.co.uk
From: "Robert Elz" <kre@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/42184 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:17 +0000
State-Changed-Why:
A fix for this has just been committed to
NetBSD HEAD (sorry about the 9 year wait). If you could test and
confirm that it behaves correctly, it would be appreciated
From: "Martin Husemann" <martin@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/42184 CVS commit: [netbsd-8] src/bin/sh
Date: Sat, 25 Aug 2018 11:45:40 +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: feedback->closed
State-Changed-By: kre@NetBSD.org
State-Changed-When: Sat, 29 Dec 2018 09:53:12 +0000
State-Changed-Why:
feedback timeout and problem believed fixed
>Unformatted:
(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.