From root@ai1.alaska.net  Sat Apr  6 20:31:18 2013
Return-Path: <root@ai1.alaska.net>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1])
	by hub.freebsd.org (Postfix) with ESMTP id 29DB5BDE
	for <FreeBSD-gnats-submit@freebsd.org>; Sat,  6 Apr 2013 20:31:18 +0000 (UTC)
	(envelope-from root@ai1.alaska.net)
Received: from ai1.alaska.net (ai1.alaska.net [209.112.188.15])
	by mx1.freebsd.org (Postfix) with ESMTP id 62E3FF2E
	for <FreeBSD-gnats-submit@freebsd.org>; Sat,  6 Apr 2013 20:31:17 +0000 (UTC)
Received: (from root@localhost)
	by ai1.alaska.net (8.14.5/8.14.5) id r36KWOJk085654;
	Sat, 6 Apr 2013 11:32:24 -0900 (AKST)
	(envelope-from root)
Message-Id: <201304062032.r36KWOJk085654@ai1.alaska.net>
Date: Sat, 6 Apr 2013 11:32:24 -0900 (AKST)
From: Joe Public <root@ai1.alaska.net>
Reply-To: Joe Public <root@ai1.alaska.net>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: /bin/sh 'while read X' loop problem
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         177674
>Category:       bin
>Synopsis:       /bin/sh 'while read X' loop problem
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    jilles
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Apr 06 20:40:00 UTC 2013
>Closed-Date:    Sun Apr 07 15:50:34 UTC 2013
>Last-Modified:  Sun Apr 07 15:50:34 UTC 2013
>Originator:     Joe Public
>Release:        FreeBSD 9.1-RELEASE i386
>Organization:
none
>Environment:
System: FreeBSD 9.1-RELEASE FreeBSD 9.1-RELEASE #0 r243826: Tue Dec 4 06:55:39 UTC 2012 root@obrian.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC i386
>Description:
There is some kind of problem with 'read' in a sh(1) loop,
but it is only demonstrated with some programs (such as mplayer).
>How-To-Repeat:
First, create a file with some valid MP3 pathanmes inside, then:

OK:   while read X; do echo    $X; done < FILEWITHMP3PATHNAMES
OK:   while read X; do ls -l   $X; done < FILEWITHMP3PATHNAMES
FAIL: while read X; do mplayer $X; done < FILEWITHMP3PATHNAMES

This last command line will fail in a mess of corruption,
and it is difficult to explain what is actually occurring.
With only 1 pathname in the file, it works OK, but with 2
or more, it increasingly results in more and more corruption.
>Fix:
I don't know what the problem is.  I tried inserting sleep(1)
commands to make the loop slow and other things, but nothing
made any difference.
>Release-Note:
>Audit-Trail:

From: poyopoyo@puripuri.plala.or.jp
To: FreeBSD-gnats-submit@freebsd.org
Cc:  
Subject: Re: bin/177674: /bin/sh 'while read X' loop problem
Date: Sun, 07 Apr 2013 05:53:49 +0900

 At Sat, 6 Apr 2013 11:32:24 -0900 (AKST),
 Joe Public wrote:
 > OK:   while read X; do echo    $X; done < FILEWITHMP3PATHNAMES
 > OK:   while read X; do ls -l   $X; done < FILEWITHMP3PATHNAMES
 > FAIL: while read X; do mplayer $X; done < FILEWITHMP3PATHNAMES
 
 The first iteration of mplayer eats up all stdin.
 You can
 
 while read X; do mplayer $X < /dev/tty; done
 
 This is not a bug at all.
 
 -- 
 kuro
State-Changed-From-To: open->closed 
State-Changed-By: jilles 
State-Changed-When: Sun Apr 7 15:48:19 UTC 2013 
State-Changed-Why:  
As described by kuro, this is not a bug. The mplayer reads from stdin, 
so that 'read' misses data. 

Try: 
while read X <&3; do mplayer $X; done 3<FILEWITHMP3PATHNAMES 


Responsible-Changed-From-To: freebsd-bugs->jilles 
Responsible-Changed-By: jilles 
Responsible-Changed-When: Sun Apr 7 15:48:19 UTC 2013 
Responsible-Changed-Why:  
Track replies. 

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