NetBSD Problem Report #54564

From jschauma@netmeister.org  Mon Sep 23 14:39:50 2019
Return-Path: <jschauma@netmeister.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id E75A47A1F9
	for <gnats-bugs@gnats.NetBSD.org>; Mon, 23 Sep 2019 14:39:49 +0000 (UTC)
Message-Id: <20190923143954.BCA718579F@panix.netmeister.org>
Date: Mon, 23 Sep 2019 10:39:54 -0400 (EDT)
From: jschauma@netmeister.org
Reply-To: jschauma@netmeister.org
To: gnats-bugs@NetBSD.org
Subject: cp of a fifo yields an empty file
X-Send-Pr-Version: 3.95

>Number:         54564
>Category:       bin
>Synopsis:       cp of a fifo yields an empty file
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Sep 23 14:40:00 +0000 2019
>Closed-Date:    Sat Apr 11 13:18:05 +0000 2020
>Last-Modified:  Thu Sep 23 10:15:01 +0000 2021
>Originator:     Jan Schaumann
>Release:        NetBSD 8.1
>Organization:

>Environment:
NetBSD apue 8.1 NetBSD 8.1 (GENERIC) #0: Fri May 31 08:43:59 UTC 2019  mkrepro@mkrepro.NetBSD.org:/usr/src/sys/arch/amd64/compile/GENERIC amd64
Architecture: x86_64
Machine: amd64
>Description:

When trying to copy a fifo, the resulting file is empty.

When cp(1) opens the fifo and begins reading, it will naturally block.
Once data is written to the fifo, cp(1) completes, but the resulting
file remains empty.

This is counter to the user's expectation that any content written
to the fifo would be copied.

>How-To-Repeat:
	mkfifo fifo
	cp fifo file &
	echo foo >fifo
	cat file
>Fix:
	Compare to what OS X cp(1) does; that yields a file
	containing 'foo'.

>Release-Note:

>Audit-Trail:
From: Robert Elz <kre@munnari.OZ.AU>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: bin/54564: cp of a fifo yields an empty file
Date: Tue, 24 Sep 2019 00:18:00 +0700

     Date:        Mon, 23 Sep 2019 14:40:00 +0000 (UTC)
     From:        jschauma@netmeister.org
     Message-ID:  <20190923144000.CE16B7A202@mollari.NetBSD.org>

 copy_file() in /bin/cp first stat's the source, and if it is empty
 (size 0), simply makes the output file, and exits.  It never attempts
 any kind of read - though it much prefers to use mmap() over read()
 preferring read() only if the file is too big to mmap() sanely.

 It should probably be smarter about the type of file it is copying,
 and simply read()/write() to EOF on the read() for anything that
 isn't a regular file.

 kre

From: Jan Schaumann <jschauma@netmeister.org>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: bin/54564: cp of a fifo yields an empty file
Date: Mon, 23 Sep 2019 13:26:54 -0400

 Robert Elz <kre@munnari.OZ.AU> wrote:

 >  copy_file() in /bin/cp first stat's the source, and if it is empty
 >  (size 0), simply makes the output file, and exits.

 Hmm, but it still blocks until data appears in the
 fifo, doesn't it?

 If cp(1) just creates an empty file and never reads,
 how come it blocks?

From: Robert Elz <kre@munnari.OZ.AU>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: bin/54564: cp of a fifo yields an empty file
Date: Tue, 24 Sep 2019 00:59:49 +0700

     Date:        Mon, 23 Sep 2019 17:30:01 +0000 (UTC)
     From:        Jan Schaumann <jschauma@netmeister.org>
     Message-ID:  <20190923173001.EF0B87A1FB@mollari.NetBSD.org>

   |  If cp(1) just creates an empty file and never reads,
   |  how come it blocks?

 It does open the source file (that's needed for both mmap() and read()
 versions) and uses fstat() rather than stat() for the size check.

 I believe that a read mode open on a fifo blocks until a writer apepars,
 but I am no fifo expert by any means, so this is just from a quick can
 of the implementation.

 That would explain the block - it isn't waiting for data to arrive, it
 is waiting for a writer to arrive.

 kre

From: "Christos Zoulas" <christos@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/54564 CVS commit: src/bin/cp
Date: Mon, 23 Sep 2019 14:01:09 -0400

 Module Name:	src
 Committed By:	christos
 Date:		Mon Sep 23 18:01:09 UTC 2019

 Modified Files:
 	src/bin/cp: utils.c

 Log Message:
 PR/54564: Jan Schaumann: cp of a fifo yields an empty file
 Don't short-circuit 0 sized stat entries if they don't belong to regular files.
 Also don't try to mmap non-regular files.


 To generate a diff of this commit:
 cvs rdiff -u -r1.46 -r1.47 src/bin/cp/utils.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: dholland@NetBSD.org
State-Changed-When: Wed, 25 Sep 2019 06:18:41 +0000
State-Changed-Why:
does christos's commit fix it?


From: Jan Schaumann <jschauma@netmeister.org>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: bin/54564 (cp of a fifo yields an empty file)
Date: Wed, 25 Sep 2019 09:51:03 -0400

 I haven't tried, but I'm sure it does.
 Feel free to close.

State-Changed-From-To: feedback->closed
State-Changed-By: maya@NetBSD.org
State-Changed-When: Sat, 11 Apr 2020 13:18:05 +0000
State-Changed-Why:
Author prefers to close the issue, and believes it is fixed.


From: "Martin Husemann" <martin@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/54564 CVS commit: [netbsd-9] src/bin/cp
Date: Thu, 23 Sep 2021 10:11:02 +0000

 Module Name:	src
 Committed By:	martin
 Date:		Thu Sep 23 10:11:02 UTC 2021

 Modified Files:
 	src/bin/cp [netbsd-9]: utils.c

 Log Message:
 Pull up following revision(s) (requested by skrll in ticket #1348):

 	bin/cp/utils.c: revision 1.47

 PR/54564: Jan Schaumann: cp of a fifo yields an empty file

 Don't short-circuit 0 sized stat entries if they don't belong to regular
 files.

 Also don't try to mmap non-regular files.


 To generate a diff of this commit:
 cvs rdiff -u -r1.46 -r1.46.2.1 src/bin/cp/utils.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.46 2020/01/03 16:35:01 leot Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2020 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.