From marcolz@crash.ilse.nl  Sat Sep  1 05:31:05 2001
Return-Path: <marcolz@crash.ilse.nl>
Received: from crash.ilse.nl (xo1.ehv.router.ilse.nl [195.18.90.227])
	by hub.freebsd.org (Postfix) with ESMTP id DC07E37B409
	for <FreeBSD-gnats-submit@freebsd.org>; Sat,  1 Sep 2001 05:31:03 -0700 (PDT)
Received: (from marcolz@localhost)
	by crash.ilse.nl (8.11.6/8.11.6) id f81ESXu50804;
	Sat, 1 Sep 2001 14:28:33 GMT
	(envelope-from marcolz)
Message-Id: <200109011428.f81ESXu50804@crash.ilse.nl>
Date: Sat, 1 Sep 2001 14:28:33 GMT
From: Marc Olzheim <marcolz@ilse.nl>
Reply-To: Marc Olzheim <marcolz@ilse.nl>
To: FreeBSD-gnats-submit@freebsd.org
Cc: <sys@ilse.nl>
Subject: sh cannot redirect to /dev/fd/1 or from /dev/fd/0
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         30247
>Category:       bin
>Synopsis:       sh cannot redirect to /dev/fd/1 or from /dev/fd/0
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Sep 01 05:40:06 PDT 2001
>Closed-Date:    Sun Jul 07 09:26:13 PDT 2002
>Last-Modified:  Sun Jul 07 09:26:13 PDT 2002
>Originator:     Marc Olzheim
>Release:        FreeBSD 5.0-CURRENT i386
>Organization:
ilse technology
>Environment:
System: FreeBSD crash.ilse.nl 5.0-CURRENT FreeBSD 5.0-CURRENT #0: Thu Aug 30 18:38:55 GMT 2001 marcolz@install0.ilse.nl:/usr/src/sys/i386/compile/zlo i386
>Description:
	FreeBSD's /bin/sh cannot redirect a filedescriptor to 'itself'.
	The only problem I have encountered throught this (this is how
	I found out), is that /usr/bin/mkdep cannot write to /dev/stdout.
	This affects FreeBSD 2.2 through 5.0 current.
>How-To-Repeat:
	In /bin/sh enter:

	echo foo > /dev/fd/1

	cat < /dev/fd/0
>Fix:
	I don't know why the open on redir.c:217 fails, so I don't
	have a fix.
>Release-Note:
>Audit-Trail:

From: Marc Olzheim <marcolz@ilse.nl>
To: freebsd-gnats-submit@FreeBSD.org
Cc:  
Subject: Re: bin/30247: sh cannot redirect to /dev/fd/1 or from /dev/fd/0
Date: Sat, 1 Sep 2001 16:56:48 +0200

 It fails beacuse /dev/fd/1 is no longer connected because it is closed
 on redir.c:148.
 
 This seems to work:
 
 --- redir.c.orig	Tue Oct  3 23:13:14 2000
 +++ redir.c	Sat Sep  1 16:14:30 2001
 @@ -143,13 +143,9 @@
  					break;
  				}
  			}
 -			if (!try) {
 +			if (!try)
  				sv->renamed[fd] = i;
 -				close(fd);
 -			}
  			INTON;
 -		} else {
 -			close(fd);
  		}
  		if (fd == 0)
  			fd0_redirected++;
 @@ -186,6 +182,7 @@
  			error("cannot open %s: %s", fname, errmsg(errno, E_OPEN));
  movefd:
  		if (f != fd) {
 +			close(fd);
  			copyfd(f, fd);
  			close(f);
  		}
 
 Marc
State-Changed-From-To: open->closed 
State-Changed-By: jon 
State-Changed-When: Sun Jul 7 09:25:19 PDT 2002 
State-Changed-Why:  

Already fixed [src/bin/sh/redir.c 1.12.2.2, 1.16] 

http://www.freebsd.org/cgi/query-pr.cgi?pr=30247 
>Unformatted:
