GNU bug report logs - #29038
df hangs on fifos/named pipes

Previous Next

Package: coreutils;

Reported by: Stephane Chazelas <stephane.chazelas <at> gmail.com>

Date: Sat, 28 Oct 2017 07:19:01 UTC

Severity: normal

Done: Pádraig Brady <P <at> draigBrady.com>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: help-debbugs <at> gnu.org (GNU bug Tracking System)
To: Stephane Chazelas <stephane.chazelas <at> gmail.com>
Subject: bug#29038: closed (Re: bug#29038: df hangs on fifos/named pipes)
Date: Mon, 30 Oct 2017 16:54:02 +0000
[Message part 1 (text/plain, inline)]
Your bug report

#29038: df hangs on fifos/named pipes

which was filed against the coreutils package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to 29038 <at> debbugs.gnu.org.

-- 
29038: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=29038
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
From: Pádraig Brady <P <at> draigBrady.com>
To: Paul Eggert <eggert <at> cs.ucla.edu>,
 Stephane Chazelas <stephane.chazelas <at> gmail.com>, 29038-done <at> debbugs.gnu.org
Cc: Martijn Dekker <martijn <at> inlv.org>
Subject: Re: bug#29038: df hangs on fifos/named pipes
Date: Mon, 30 Oct 2017 09:53:01 -0700
On 29/10/17 23:16, Paul Eggert wrote:
> Pádraig Brady wrote:
> 
>> I suppose we could stat() and if that succeeds && !fifo, only then call open() ?
>> Patch to do that is attached.
> 
> Better is to use open with O_NONBLOCK, as this avoids interpreting the file name 
> twice in the usual case. Better yet is to use O_PATH if available, as this 
> avoids interpreting the file name twice even when the file is unreadable or is a 
> FIFO that would block. Also, the comment just before the code should be changed 
> to match the altered code. Proposed followup patch attached.
> 
> It is puzzling that df calls fstat or stat, when it should just be calling 
> fstatfs or statfs. But that is a different matter.

I pushed my change with the comments fixed up.

I thought about O_NONBLOCK and O_PATH but thought these might not
induce or wait for the auto mount to occur.

thanks for the review,
Pádraig

marking this as done...


[Message part 3 (message/rfc822, inline)]
From: Stephane Chazelas <stephane.chazelas <at> gmail.com>
To: bug-coreutils <at> gnu.org
Cc: Martijn Dekker <martijn <at> inlv.org>
Subject: df hangs on fifos/named pipes
Date: Sat, 28 Oct 2017 08:18:11 +0100
test case:

   mkfifo p
   df p

That hangs, unless you make "p" non-readable or some other process
has the fifo open in write mode.

The reason is that df tries to open the fifo in read-only mode,
according to comments in the source code so as to trigger a
potential automout.

That goes back to this commit:

> commit dbd17157d7e693b8de9737f802db0e235ff5a3e6
> Author: Tomas Smetana <t.smetana <at> gmail.com>
> Date:   Tue Apr 28 11:21:49 2009 +0200
> 
>     df: use open(2), not stat, to trigger automounting
> 
>     * src/df.c (main): When iterating over command-line arguments,
>     attempting to ensure each backing file system is mounted, use
>     open, not stat.  stat is no longer sufficient to trigger
>     automounting, in some cases.  Based on a suggestion from Ian Kent.
>     More details in http://bugzilla.redhat.com/497830

More info at the bugzilla link.

It's arguable whether df, a reporting tool, should have such a
side effect as automounting a file system.

The fifo issue though is a bug IMO, especially considering that
POSIX explicitely says that df should work on fifos.

Here, it may be enough to add the O_DIRECTORY flag to open()
where available if we only care about automounting files of type
directory (or portably use opendir()).

Or use O_PATH  on Linux 3.6+ followed by openat() on non-fifos if
open(O_PATH) is not enough to trigger the automount in the
unlikely event we care about automounting non-directory files
(and report their disk usage).

Or not open() at all, and not automount file systems.

Note that busybox, heirloom or ast-open df implementations on
Linux don't have the problem (and presumably don't automount
file systems). Nor does FreeBSD.

Reproduced with:

$ df --version
df (GNU coreutils) 8.25

and:

$ df --version
df (GNU coreutils) 8.27.46-e13fe

That was discovered by Martijn Dekker, CCed, when looking for a
portable way to identify the file system of an arbitrary file.

-- 
Stephane



This bug report was last modified 7 years and 210 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.