From "."@babolo.ru  Thu Nov 15 06:10:21 2012
Return-Path: <"."@babolo.ru>
Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52])
	by hub.freebsd.org (Postfix) with ESMTP id 467C589E
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 15 Nov 2012 06:10:21 +0000 (UTC)
	(envelope-from "."@babolo.ru)
Received: from smtp1.babolo.ru (smtp1.babolo.ru [195.9.14.139])
	by mx1.freebsd.org (Postfix) with ESMTP id B91DC8FC12
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 15 Nov 2012 06:10:20 +0000 (UTC)
Received: from cicuta.babolo.ru (cicuta.babolo.ru [194.58.246.5])
	by smtp1.babolo.ru (8.14.2/8.14.2) with SMTP id qAF63tF7043840
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 15 Nov 2012 10:03:55 +0400 (MSK)
	(envelope-from babolo@babolo.ru)
Received: (nullmailer pid 95454 invoked by uid 136);
	Thu, 15 Nov 2012 05:58:48 -0000
Message-Id: <1352959128.149421.95453.nullmailer@babolo.ru>
Date: Thu, 15 Nov 2012 09:58:48 +0400
From: Aleksandr A Babaylov <.@babolo.ru>
Reply-To: Aleksandr A Babaylov <.@babolo.ru>
To: FreeBSD-gnats-submit@freebsd.org
Subject: ``here-document'' does not works in FreeBSD 9 /bin/sh
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         173642
>Category:       bin
>Synopsis:       sh(1): ``here-document'' does not works in FreeBSD 9 /bin/sh
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    jilles
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Nov 15 06:20:00 UTC 2012
>Closed-Date:    Sat Mar 01 13:51:22 UTC 2014
>Last-Modified:  Sat Mar 01 13:51:22 UTC 2014
>Originator:     Aleksandr A Babaylov
>Release:        FreeBSD 9.1-PRERELEASE amd64
>Organization:
private
>Environment:
FreeBSD aahz.babolo.ru 9.1-PRERELEASE FreeBSD 9.1-PRERELEASE #0: Wed Oct 31 18:43:14 MSK 2012     babolo@aahz.babolo.ru:/tmp/babolo/usr/src/sys/blut  amd64


>Description:
	``here-document'' does not works in sh
>How-To-Repeat:
====================
aahz>cat $TMPDIR/t
#!/bin/sh

5<< EOF
sduyhvb
EOF
/bin/ls -l /dev/fd/5
/bin/cat /dev/fd/5

aahz>uname -a
FreeBSD aahz.babolo.ru 9.1-PRERELEASE FreeBSD 9.1-PRERELEASE #0: Wed Oct 31 18:43:14 MSK 2012     babolo@aahz.babolo.ru:/tmp/babolo/usr/src/sys/blut  amd64
aahz>env LC_ALL=C sh $TMPDIR/t
ls: /dev/fd/5: Bad file descriptor
cat: /dev/fd/5: Bad file descriptor
aahz>df | grep fdescfs
fdescfs                           1        1         0   100%    /dev/fd
====================

On older releases it works:

====================
skeeve>cat $TMPDIR/t
#!/bin/sh
5<< EOF
sduyhvb
EOF
/bin/ls -l /dev/fd/5
/bin/cat /dev/fd/5

skeeve>uname -a
FreeBSD skeeve.babolo.ru 8.3-STABLE FreeBSD 8.3-STABLE #0: Mon Oct 22 14:20:22 MSK 2012     babolo@skeeve.babolo.ru:/tmp/babolo/usr/src/sys/blut  amd64
skeeve>env LC_ALL=C sh $TMPDIR/t
cr-xr-xr-x  1 root  wheel    0,   8 Nov 15 08:10 /dev/fd/5
sduyhvb
skeeve>df | grep fdescfs
fdescfs                          1        1        0   100%    /dev/fd
====================

====================
cicuta>cat $TMPDIR/t
#!/bin/sh

5<< EOF
sduyhvb
EOF
/bin/ls -l /dev/fd/5
/bin/cat /dev/fd/5

cicuta>uname -a
FreeBSD cicuta.babolo.ru 7.2-STABLE FreeBSD 7.2-STABLE #0: Wed May 27 02:13:01 MSD 2009     babolo@cicuta.babolo.ru:/tmp/babolo/usr/src/sys/cicuta  i386
cicuta>env LC_ALL=C sh $TMPDIR/t
p---------  1 babolo  wheel  8 Nov 15 09:48 /dev/fd/5
sduyhvb
cicuta>df | grep fdescfs
fdescfs                            1          1         0   100%    /dev/fd
====================

It seen by kdump, that 5 descriptor in FreeBSD 9 closed before using.

>Fix:

	Use /bin/sh from older version?


>Release-Note:
>Audit-Trail:

From: Jilles Tjoelker <jilles@stack.nl>
To: bug-followup@FreeBSD.org, Aleksandr A Babaylov <"."@babolo.ru>
Cc:  
Subject: bin/173642: ``here-document'' does not works in FreeBSD 9 /bin/sh
Date: Sat, 17 Nov 2012 23:51:54 +0100

 In PR bin/173642:
 > As of FreeBSD 9.0, the below script fails (with fdescfs mounted):
 
 > 5<<EOF
 > foo
 > EOF
 > cat /dev/fd/5
 
 This script took advantage of a bug in sh that has been fixed. A
 redirection should only apply for the duration of the command it is
 attached to, except if that command is the builtin "exec". This includes
 commands consisting solely of redirections (here-documents or other
 kinds). Before 9.0, sh did not handle this properly if the fd was not
 open before a redirection attached to some kinds of commands.
 
 Note that the script will not work even with the older sh if fd 5 is
 already open, for example
   sh your-script 5</dev/null
 
 The fix is to replace the line
   5<<EOF
 with
   exec 5<<EOF
 This will also work with the older sh, fixing the problems if fd 5 is
 already open.
 
 I do not plan to merge the bugfix in sh to stable/8.
 
 -- 
 Jilles Tjoelker
State-Changed-From-To: open->closed 
State-Changed-By: jilles 
State-Changed-When: Sat Mar 1 13:50:04 UTC 2014 
State-Changed-Why:  
This is not a bug in FreeBSD but in the script, as noted in my 
reply from 17 Nov 2012. 


Responsible-Changed-From-To: freebsd-bugs->jilles 
Responsible-Changed-By: jilles 
Responsible-Changed-When: Sat Mar 1 13:50:04 UTC 2014 
Responsible-Changed-Why:  
Track replies. 

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