NetBSD Problem Report #47065
From www@NetBSD.org Sat Oct 13 09:21:22 2012
Return-Path: <www@NetBSD.org>
Received: from mail.netbsd.org (mail.netbsd.org [149.20.53.66])
by www.NetBSD.org (Postfix) with ESMTP id 0BC1263E059
for <gnats-bugs@gnats.NetBSD.org>; Sat, 13 Oct 2012 09:21:22 +0000 (UTC)
Message-Id: <20121013092121.320AC63DD3F@www.NetBSD.org>
Date: Sat, 13 Oct 2012 09:21:21 +0000 (UTC)
From: iku.iwasa@gmail.com
Reply-To: iku.iwasa@gmail.com
To: gnats-bugs@NetBSD.org
Subject: /bin/sh returns success for Bad file descriptor
X-Send-Pr-Version: www-1.0
>Number: 47065
>Category: bin
>Synopsis: /bin/sh returns success for Bad file descriptor
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: kre
>State: closed
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Sat Oct 13 09:25:00 +0000 2012
>Closed-Date: Mon Jun 13 11:21:10 +0000 2016
>Last-Modified: Mon Jun 13 11:21:10 +0000 2016
>Originator: Iku Iwasa
>Release: 6.99.11
>Organization:
>Environment:
NetBSD localhost 6.99.11 NetBSD 6.99.11 (GENERIC) #0: Sat Sep 29 15:21:39 JST 2012 root@localhost:/usr/obj/sys/arch/i386/compile/GENERIC i386
>Description:
/bin/sh returns 0 for the following Bad file descriptor case while other shells not.
-----------------------------------------
$ /bin/sh -c 'cat <&3'; echo $?
sh: 3: Bad file descriptor
0
$ /bin/ksh -c 'cat <&3'; echo $?
/bin/ksh: <&3 : bad file descriptor
1
$ /usr/pkg/bin/bash -c 'cat <&3'; echo $?
/usr/pkg/bin/bash: 3: Bad file descriptor
1
$ /usr/pkg/bin/zsh -c 'cat <&3'; echo $?
zsh:1: 3: bad file descriptor
1
-----------------------------------------
>How-To-Repeat:
$ /bin/sh -c 'cat <&3'; echo $?
sh: 3: Bad file descriptor
0
>Fix:
I am not sure, but exerrno should be set before error() in copyfd()?
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: bin-bug-people->kre
Responsible-Changed-By: kre@NetBSD.org
Responsible-Changed-When: Fri, 13 May 2016 02:42:03 +0000
Responsible-Changed-Why:
I am (for now) handling this PR
State-Changed-From-To: open->analyzed
State-Changed-By: kre@NetBSD.org
State-Changed-When: Fri, 13 May 2016 02:42:03 +0000
State-Changed-Why:
This turns out to be mostly a duplicate of PR bin/39466
The problem relates to the way that a vfork'd process reports its status
when it dies because of a shell error (like redirection failure.)
All of "sh -c '(cat <&3)'" "sh -c '(cat) <&3'" "sh -c 'exec cat <&3'"
worked, because one way or another, they avoided the specific situation
that fails.
I believe I might have a fix (for both this and bin/39466 - the same fix)
but it needs a lot of testing before it gets to see the light of day.
Stay tuned...
From: "Robert Elz" <kre@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/47065 CVS commit: src/bin/sh
Date: Wed, 1 Jun 2016 02:50:03 +0000
Module Name: src
Committed By: kre
Date: Wed Jun 1 02:50:03 UTC 2016
Modified Files:
src/bin/sh: error.c
Log Message:
PR bin/47065 PR bin/39466
When the shell exits after an error (when that is the right thing for
it to do) ensure that it never does exit(0).
To generate a diff of this commit:
cvs rdiff -u -r1.38 -r1.39 src/bin/sh/error.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
State-Changed-From-To: analyzed->feedback
State-Changed-By: kre@NetBSD.org
State-Changed-When: Wed, 01 Jun 2016 05:18:50 +0000
State-Changed-Why:
This should be fixed now, in current, can you confirm?
From: iquiw <iku.iwasa@gmail.com>
To: gnats-bugs@netbsd.org, kre@netbsd.org, netbsd-bugs@netbsd.org,
gnats-admin@netbsd.org
Cc:
Subject: Re: bin/47065 (/bin/sh returns success for Bad file descriptor)
Date: Mon, 13 Jun 2016 18:45:28 +0900
I confirmed the fix.
Thank you.
On Wed, Jun 1, 2016 at 2:18 PM, <kre@netbsd.org> wrote:
> Synopsis: /bin/sh returns success for Bad file descriptor
>
> State-Changed-From-To: analyzed->feedback
> State-Changed-By: kre@NetBSD.org
> State-Changed-When: Wed, 01 Jun 2016 05:18:50 +0000
> State-Changed-Why:
> This should be fixed now, in current, can you confirm?
>
>
>
State-Changed-From-To: feedback->closed
State-Changed-By: wiz@NetBSD.org
State-Changed-When: Mon, 13 Jun 2016 11:21:10 +0000
State-Changed-Why:
Confirmed fixed, thanks!
>Unformatted:
(Contact us)
$NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2014
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.