From debbugs-submit-bounces@debbugs.gnu.org Sat Oct 28 03:18:28 2017 Received: (at submit) by debbugs.gnu.org; 28 Oct 2017 07:18:28 +0000 Received: from localhost ([127.0.0.1]:37991 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e8LO0-0007pA-3E for submit@debbugs.gnu.org; Sat, 28 Oct 2017 03:18:28 -0400 Received: from eggs.gnu.org ([208.118.235.92]:45792) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e8LNz-0007ow-21 for submit@debbugs.gnu.org; Sat, 28 Oct 2017 03:18:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e8LNs-000087-P1 for submit@debbugs.gnu.org; Sat, 28 Oct 2017 03:18:21 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, T_DKIM_INVALID autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:45271) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e8LNs-000083-Lt for submit@debbugs.gnu.org; Sat, 28 Oct 2017 03:18:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36763) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e8LNr-0002pk-FQ for bug-coreutils@gnu.org; Sat, 28 Oct 2017 03:18:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e8LNo-00006N-9W for bug-coreutils@gnu.org; Sat, 28 Oct 2017 03:18:19 -0400 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]:54670) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e8LNo-00005t-2g for bug-coreutils@gnu.org; Sat, 28 Oct 2017 03:18:16 -0400 Received: by mail-wm0-x241.google.com with SMTP id r68so7255437wmr.3 for ; Sat, 28 Oct 2017 00:18:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=B+/RpqtPmy/OtslHmdKRDdXnhWVmvNfBLxjFnsd1hME=; b=QPEQxWeiHaK9n4EagX2t/Y607sUdWpBMLtbTsZ+axAjJk61uJXJOCPeeKdFO0talkv MCT8okzk0PQJwmElHys2wwDGbMD4RgVHkyhYnmi0g78zhMW64pYF4pKPIWkGJn9pzhnp vmQzPPYgleGHggKVjcDA1jQPgW8MvdIglsnRibbhv8C7X9yxT/qo4hOonf3y7nQCdST3 pbFEZGXPZxaWj2yK3z2DjLRNBiWVfp/yPrzBM18zvAy8IYcN9e2dr7IT84ktKxIzvxOT VmfFwgOMzNe1Ni/zS+zKEjCvdwX2HMNmk8+lVtNSWi2mzd2XS8Z5cWF0+OXsobIwqnfk zg8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=B+/RpqtPmy/OtslHmdKRDdXnhWVmvNfBLxjFnsd1hME=; b=sz+6rICTibterMTWNkr8X9AYgYYkLZDmdzErcZeS3ueZOKzWu7Onm5oGVSzX4GAV/b r0GBjt99NZnWECI6P/BJwu13F4/QTG2ULuC+OFAa0mpfM1kLXA1xFMLbPH5AENqdDMvo shS2HHHxuja5KsckVnfUET/HQmBJMcUZXiKVT8Hd+CfF31tdDGu8JufaeFH304G1v2Ep tuyYfp5vTRWqNq7Ha8pbRSO7cK/8jiwrZX2d44JepXO2VcCqkQxPk28qSg9pyi3Nn3u9 v5Z/hk9vvB2UbjhTLfB4K0MjaYNQSMlOJbJzq8vbSGYL0RGhJA1UVG4ApRxDHy0ZvVZt Ij6g== X-Gm-Message-State: AMCzsaW/uEfvXkXdRAL/QJsDWBtLs/kTvTkmn1zG522j3d5KVqfQ0yu1 pgqoc7OUHqnLY0R9vH9joOjzMw== X-Google-Smtp-Source: ABhQp+R2WPdTPw8J3f4n0JG/fRRJ6aWQT8s3hn8L8NQytwiSz/9JQLg6VseTy6SW5HNiuE975eX0iw== X-Received: by 10.80.136.49 with SMTP id b46mr3724358edb.238.1509175094327; Sat, 28 Oct 2017 00:18:14 -0700 (PDT) Received: from chaz.gmail.com ([90.198.158.87]) by smtp.gmail.com with ESMTPSA id u14sm5341043edd.47.2017.10.28.00.18.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 28 Oct 2017 00:18:12 -0700 (PDT) Date: Sat, 28 Oct 2017 08:18:11 +0100 From: Stephane Chazelas To: bug-coreutils@gnu.org Subject: df hangs on fifos/named pipes Message-ID: <20171028071811.GA4783@chaz.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -4.0 (----) X-Debbugs-Envelope-To: submit Cc: Martijn Dekker X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -4.0 (----) 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 > 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 From debbugs-submit-bounces@debbugs.gnu.org Sun Oct 29 18:34:30 2017 Received: (at 29038) by debbugs.gnu.org; 29 Oct 2017 22:34:30 +0000 Received: from localhost ([127.0.0.1]:41058 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e8wA1-0002Ex-Vc for submit@debbugs.gnu.org; Sun, 29 Oct 2017 18:34:30 -0400 Received: from mail.magicbluesmoke.com ([82.195.144.49]:39758) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e8wA0-0002Ep-3D for 29038@debbugs.gnu.org; Sun, 29 Oct 2017 18:34:28 -0400 Received: from localhost.localdomain (c-73-158-116-184.hsd1.ca.comcast.net [73.158.116.184]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.magicbluesmoke.com (Postfix) with ESMTPSA id 3854D4B02; Sun, 29 Oct 2017 22:34:26 +0000 (GMT) Subject: Re: bug#29038: df hangs on fifos/named pipes To: Stephane Chazelas , 29038@debbugs.gnu.org References: <20171028071811.GA4783@chaz.gmail.com> From: =?UTF-8?Q?P=c3=a1draig_Brady?= Message-ID: <0a956ac7-c23d-bad6-09b9-86becfc1b1e0@draigBrady.com> Date: Sun, 29 Oct 2017 15:34:23 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 In-Reply-To: <20171028071811.GA4783@chaz.gmail.com> Content-Type: multipart/mixed; boundary="------------4BC922A4BA61738DA92B103F" X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 29038 Cc: Martijn Dekker X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) This is a multi-part message in MIME format. --------------4BC922A4BA61738DA92B103F Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 8bit On 28/10/17 00:18, Stephane Chazelas wrote: > 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 >> 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. > Yes we shouldn't hang. RE side effects, open() is a fairly innocuous operation, and we expect stat() to have side effects to auto mount. (Note we avoid stat() with non specified arguments if possible due to this): https://git.sv.gnu.org/gitweb/?p=coreutils.git;a=commitdiff;h=v8.27-92-ga19ff5d I suppose we could stat() and if that succeeds && !fifo, only then call open() ? Patch to do that is attached. cheers, Pádraig --------------4BC922A4BA61738DA92B103F Content-Type: text/x-patch; name="df-fifo-hang.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="df-fifo-hang.patch" =46rom 2771d66e4fdb2e2d158d092ead543638115971f9 Mon Sep 17 00:00:00 2001 From: =3D?UTF-8?q?P=3DC3=3DA1draig=3D20Brady?=3D Date: Sun, 29 Oct 2017 15:29:05 -0700 Subject: [PATCH] df: fix hang with fifo argument * src/df.c (main): stat() before open(), and avoid the optional open when given a fifo argument. * tests/df/unreadable.sh: Add a test case. * NEWS: Mention the fix. Fixes https://bugs.gnu.org/29038 --- NEWS | 3 +++ src/df.c | 13 ++++++++----- tests/df/unreadable.sh | 3 +++ 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/NEWS b/NEWS index 806e3ef..3e6704d 100644 --- a/NEWS +++ b/NEWS @@ -12,6 +12,9 @@ GNU coreutils NEWS -= *- outline -*- invalidated. [bug introduced for "direct" in coreutils-7.5, and with the "nocache" implementation in coreutils-8.11] =20 + df no longer hangs when given a fifo argument. + [bug introduced in coreutils-7.3] + ptx -S no longer infloops for a pattern which returns zero-length matc= hes. [the bug dates back to the initial implementation] =20 diff --git a/src/df.c b/src/df.c index 7345bc9..ee04d51 100644 --- a/src/df.c +++ b/src/df.c @@ -1710,16 +1710,19 @@ main (int argc, char **argv) { /* Prefer to open with O_NOCTTY and use fstat, but fall back on using "stat", in case the file is unreadable. */ - int fd =3D open (argv[i], O_RDONLY | O_NOCTTY); - if ((fd < 0 || fstat (fd, &stats[i - optind])) - && stat (argv[i], &stats[i - optind])) + if (stat (argv[i], &stats[i - optind])) { error (0, errno, "%s", quotef (argv[i])); exit_status =3D EXIT_FAILURE; argv[i] =3D NULL; } - if (0 <=3D fd) - close (fd); + else if (! S_ISFIFO (stats[i - optind].st_mode)) + { + /* open() is needed to automount in some cases. */ + int fd =3D open (argv[i], O_RDONLY | O_NOCTTY); + if (0 <=3D fd) + close (fd); + } } } =20 diff --git a/tests/df/unreadable.sh b/tests/df/unreadable.sh index c28cdc9..fb4c91c 100755 --- a/tests/df/unreadable.sh +++ b/tests/df/unreadable.sh @@ -24,6 +24,9 @@ touch unreadable || fail=3D1 chmod a-r unreadable || fail=3D1 df unreadable || fail=3D1 =20 +mkfifo_or_skip_ fifo +timeout 10 df fifo || fail=3D1 + test "$fail" =3D 1 && dump_mount_list_ =20 Exit $fail --=20 2.9.3 --------------4BC922A4BA61738DA92B103F-- From debbugs-submit-bounces@debbugs.gnu.org Sun Oct 29 19:22:20 2017 Received: (at 29038) by debbugs.gnu.org; 29 Oct 2017 23:22:21 +0000 Received: from localhost ([127.0.0.1]:41066 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e8wuK-0003Ox-OF for submit@debbugs.gnu.org; Sun, 29 Oct 2017 19:22:20 -0400 Received: from mail-qk0-f181.google.com ([209.85.220.181]:49335) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e8wuJ-0003Oi-8b for 29038@debbugs.gnu.org; Sun, 29 Oct 2017 19:22:19 -0400 Received: by mail-qk0-f181.google.com with SMTP id q83so14135084qke.6 for <29038@debbugs.gnu.org>; Sun, 29 Oct 2017 16:22:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc:content-transfer-encoding; bh=gFqiCeokqPcSRELsxcLcsvXQlAlMuXWtPXd7n21+/m4=; b=FIN6/5/OT/hCd+M/AiHxJrh1wjMiShkrwqELstlGg4TPovXi3eEBYgycyR1Mxw3M9A aGPdMyfdJ/wnGms64beyPbwcptN1PusLZfUH2ktbVnp+a9xMW2k3UyCSJP/kod0rVukF ZySFo7V328SOoZzDsFl/+7tHK9OAwQjgjR4bFmoLvxlJ1BqOAAsUFPHjM31ADA2p6OyC 1XeoJnX/PkeyPODitAiDIRAGOkLv4sqCUxRWv+bq7hMJwRKjjej4HTMSzxmWXWJn3GdP DzXUyWktroqYVnEp2hpIrW58Bk+WgxyDiIYEwZJa+SlYBFTE7KW7Makm1nXwAbeOSKhZ qhUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc:content-transfer-encoding; bh=gFqiCeokqPcSRELsxcLcsvXQlAlMuXWtPXd7n21+/m4=; b=pCRi2zkDj5OebPjBPEcpzIFzL+onRy2sRQHi3zP3439B9/CtA2sWroiAy2WgUAzW7p UMQkE/Z0TyiGu5u8Cbij797eheQiAzWimxz7oHe8TUZvOF6jihNb6ceEXp4y6bKFq24r +A7bLek1LL8e1MWqpNZVHdybjN+jBOUIrq38ywwuGfuEjTK7h06jdB1Q+IkrpFAry1E2 o8UMbzdDNCtMh3LV1LG04z+al+/TkLjDRNyfgvLfbWlVDFItAOiFY/4LcZNw6yArVYe8 yTKzba9XAoJGFKNCElQxQJw5vNvIgfr/XiYLdFXRAOeatm2YXabwODo6RokrrQyavdt2 PJew== X-Gm-Message-State: AMCzsaV5NfYU1CZWLvTjbDp5/Q3NJCoCc54c5YK3aACwqlwvkLT1AOfs VXihPMvePEDUVmlSwdkZC3mYdUOAhuv/9B3hKD8= X-Google-Smtp-Source: ABhQp+StXE+7hlthxSkIMpa2uuH2ylnFCVABzGZM4FeQpkkHNKQ1WBwRZSpmCOvvqLWVC7/cBo4anHHmTE4NhGo7M/w= X-Received: by 10.55.148.70 with SMTP id w67mr10855555qkd.102.1509319333715; Sun, 29 Oct 2017 16:22:13 -0700 (PDT) MIME-Version: 1.0 Received: by 10.55.198.145 with HTTP; Sun, 29 Oct 2017 16:21:52 -0700 (PDT) In-Reply-To: <0a956ac7-c23d-bad6-09b9-86becfc1b1e0@draigBrady.com> References: <20171028071811.GA4783@chaz.gmail.com> <0a956ac7-c23d-bad6-09b9-86becfc1b1e0@draigBrady.com> From: Jim Meyering Date: Sun, 29 Oct 2017 16:21:52 -0700 X-Google-Sender-Auth: 1xSQSjmn2lLceCLcpkMlr4CIvmg Message-ID: Subject: Re: bug#29038: df hangs on fifos/named pipes To: =?UTF-8?Q?P=C3=A1draig_Brady?= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Score: 0.7 (/) X-Debbugs-Envelope-To: 29038 Cc: 29038@debbugs.gnu.org, Martijn Dekker , Stephane Chazelas X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.7 (/) On Sun, Oct 29, 2017 at 3:34 PM, P=C3=A1draig Brady wrot= e: ... >> That was discovered by Martijn Dekker, CCed, when looking for a >> portable way to identify the file system of an arbitrary file. > > Yes we shouldn't hang. > > RE side effects, open() is a fairly innocuous operation, > and we expect stat() to have side effects to auto mount. > (Note we avoid stat() with non specified arguments if possible due to thi= s): > https://git.sv.gnu.org/gitweb/?p=3Dcoreutils.git;a=3Dcommitdiff;h=3Dv8.27= -92-ga19ff5d > > I suppose we could stat() and if that succeeds && !fifo, only then call o= pen() ? > Patch to do that is attached. Sounds good. Patch looks fine to me. Thanks! From debbugs-submit-bounces@debbugs.gnu.org Mon Oct 30 02:17:00 2017 Received: (at 29038) by debbugs.gnu.org; 30 Oct 2017 06:17:00 +0000 Received: from localhost ([127.0.0.1]:41209 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e93Nb-0006k7-VR for submit@debbugs.gnu.org; Mon, 30 Oct 2017 02:17:00 -0400 Received: from zimbra.cs.ucla.edu ([131.179.128.68]:43674) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e93Na-0006ju-0M for 29038@debbugs.gnu.org; Mon, 30 Oct 2017 02:16:58 -0400 Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 170C816069E; Sun, 29 Oct 2017 23:16:52 -0700 (PDT) Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id QSf-8jJERBAk; Sun, 29 Oct 2017 23:16:51 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 451921606A0; Sun, 29 Oct 2017 23:16:51 -0700 (PDT) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id mXEFqYPzRou7; Sun, 29 Oct 2017 23:16:51 -0700 (PDT) Received: from [192.168.1.9] (unknown [47.154.18.85]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id 17B22160576; Sun, 29 Oct 2017 23:16:51 -0700 (PDT) Subject: Re: bug#29038: df hangs on fifos/named pipes To: =?UTF-8?Q?P=c3=a1draig_Brady?= , Stephane Chazelas , 29038@debbugs.gnu.org References: <20171028071811.GA4783@chaz.gmail.com> <0a956ac7-c23d-bad6-09b9-86becfc1b1e0@draigBrady.com> From: Paul Eggert Organization: UCLA Computer Science Department Message-ID: Date: Sun, 29 Oct 2017 23:16:50 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: <0a956ac7-c23d-bad6-09b9-86becfc1b1e0@draigBrady.com> Content-Type: multipart/mixed; boundary="------------27112AF7C893E951942456EA" Content-Language: en-US X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 29038 Cc: Martijn Dekker X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.3 (--) This is a multi-part message in MIME format. --------------27112AF7C893E951942456EA Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable P=C3=A1draig 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 fi= le name=20 twice in the usual case. Better yet is to use O_PATH if available, as thi= s=20 avoids interpreting the file name twice even when the file is unreadable = or is a=20 FIFO that would block. Also, the comment just before the code should be c= hanged=20 to match the altered code. Proposed followup patch attached. It is puzzling that df calls fstat or stat, when it should just be callin= g=20 fstatfs or statfs. But that is a different matter. --------------27112AF7C893E951942456EA Content-Type: text/x-patch; name="0001-df-improve-fix-for-FIFOs.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="0001-df-improve-fix-for-FIFOs.patch" =46rom c02f0e6009d7d77ee7a8e1299e03ca10a477c9e4 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sun, 29 Oct 2017 23:09:49 -0700 Subject: [PATCH] df: improve fix for FIFOs * src/df.c (main): Use O_PATH if available. Otherwise, use O_NONBLOCK. Either way, this avoids the need to interpret the file name twice. --- src/df.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/df.c b/src/df.c index ee04d51..cab1958 100644 --- a/src/df.c +++ b/src/df.c @@ -1708,21 +1708,25 @@ main (int argc, char **argv) stats =3D xnmalloc (argc - optind, sizeof *stats); for (int i =3D optind; i < argc; ++i) { - /* Prefer to open with O_NOCTTY and use fstat, but fall back - on using "stat", in case the file is unreadable. */ - if (stat (argv[i], &stats[i - optind])) +#if O_PATH + int oflag =3D O_PATH; + bool skip_stat =3D true; +#else + /* Fall back on stat in case the file is unreadable or is a + FIFO that would block. */ + int oflag =3D O_RDONLY | O_NOCTTY | O_NONBLOCK; + bool skip_stat =3D false; +#endif + int fd =3D open (argv[i], oflag); + if ((fd < 0 || fstat (fd, &stats[i - optind]) !=3D 0) + && (skip_stat || stat (argv[i], &stats[i - optind]) !=3D 0= )) { error (0, errno, "%s", quotef (argv[i])); exit_status =3D EXIT_FAILURE; argv[i] =3D NULL; } - else if (! S_ISFIFO (stats[i - optind].st_mode)) - { - /* open() is needed to automount in some cases. */ - int fd =3D open (argv[i], O_RDONLY | O_NOCTTY); - if (0 <=3D fd) - close (fd); - } + if (0 <=3D fd) + close (fd); } } =20 --=20 2.7.4 --------------27112AF7C893E951942456EA-- From debbugs-submit-bounces@debbugs.gnu.org Mon Oct 30 03:06:21 2017 Received: (at 29038) by debbugs.gnu.org; 30 Oct 2017 07:06:21 +0000 Received: from localhost ([127.0.0.1]:41240 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e949N-0007w6-15 for submit@debbugs.gnu.org; Mon, 30 Oct 2017 03:06:21 -0400 Received: from mail-wm0-f43.google.com ([74.125.82.43]:53315) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e949L-0007vr-Ds for 29038@debbugs.gnu.org; Mon, 30 Oct 2017 03:06:19 -0400 Received: by mail-wm0-f43.google.com with SMTP id r196so14173709wmf.2 for <29038@debbugs.gnu.org>; Mon, 30 Oct 2017 00:06:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=Q2oWc79GBXPQrgHUi6hAVKB3DW/tyueI0PiHJ/XIoC8=; b=LmJgWzTqHyP/JLWqp5oYjLUBvlgrvHNVoubGZvwsKbaeLbCYon5/wjFDWc8pxSwP9d nf1WZqxUlduTjF1nxWFXhRaJNhV4y8RQ+oZqhhV2xfOR99MbTbLbHD/WLemIpfpStWmA GYLLQfQhyLlQD57QW2wm+rDvYy+brBR6Lm/fTAv+Dqm6RjVUeUzqSCLOXiCwlG8RVAZ3 yY8QwZs4IAyWK/T34e9dUHyVLZQ/e98QtgPxlcYuGj+p6ofWSedk7fBBGn9ErDS7Ac0w p6vqzE/qZmIq/v5RRBpDGNNETcS3ScQm2il7Gxl5qUwVCRjEHjEfnyCTvmPpxk/wSguc 3Gvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=Q2oWc79GBXPQrgHUi6hAVKB3DW/tyueI0PiHJ/XIoC8=; b=lC9zUXx7LL0Vt6YfAQ0VJSRZQNcX9l0IRv604IJLq1A3XzJtUNJh/Ria8NNLTb+QM5 CJ3nn0jLPqA7teKXIHkz23RLzr3cLAbM9rEuueErljSugVnXe2gXVCCWiCLPHHpeWJ2j rKDoMKBlbovS+wQv9qx5EVVDa0ncDK3XJUNujqptEM6thkHe/FZg/UG9XwD1fdkoUZGY x3J/63KnPr6HWCxyshRdd9qy4l4vb5mhtIxSfYkXK3uHB8i3Rm3JIG9GSQVrZYHdU+RF fWEIC3YwujCnSpx+3cKrI7+lwt6bDuAHNBPRb0DZo+TmZxMaZH7Ri3voXlrN2mUMMhLG GK+w== X-Gm-Message-State: AMCzsaX9yKBIeCcSJpqeB3Zi1QNelnuNz1U9crr+qk6bbNRo6rx4jryT fOynGvTKjONDMKnUlKkC5j8= X-Google-Smtp-Source: ABhQp+RTdTxBu6KvqeCVX3DqPrMrheFCmQBCxvIV/O2Rf9dmJPaAjcxFj6ysrtnNsnOsTuHCFwz19g== X-Received: by 10.80.183.148 with SMTP id h20mr10695177ede.178.1509347173680; Mon, 30 Oct 2017 00:06:13 -0700 (PDT) Received: from chaz.gmail.com ([90.198.158.87]) by smtp.gmail.com with ESMTPSA id f39sm11423342edf.83.2017.10.30.00.06.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 30 Oct 2017 00:06:12 -0700 (PDT) Date: Mon, 30 Oct 2017 07:06:10 +0000 From: Stephane Chazelas To: Paul Eggert Subject: Re: bug#29038: df hangs on fifos/named pipes Message-ID: <20171030070610.GA5068@chaz.gmail.com> References: <20171028071811.GA4783@chaz.gmail.com> <0a956ac7-c23d-bad6-09b9-86becfc1b1e0@draigBrady.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 29038 Cc: Martijn Dekker , 29038@debbugs.gnu.org, =?iso-8859-1?Q?P=E1draig?= Brady X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.0 (/) 2017-10-29 23:16:50 -0700, Paul Eggert: > 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. That would still have the unwanted side effect of instantiating (and kill thereafter) the pipe when opening a fifo that has a writer and no reader. As in, if some process does a fd = open("fifo", O_WRONLY) The "df fifo" would cause that open() to return, and the next write() to it possibly cause a SIGPIPE because df is already gone. It's different for O_DIRECTORY as the open() would fail on fifos (it also fails if you don't have read permission, which is another advantage of using O_PATH I suppose) > 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. Note that according to the man page, fstat() on fds open with O_PATH only works since Linux 3.6. Note that we're already interpreting the file path twice as we're not using fstatfs (as we wouldn't want to cause a "too many open files" situation I suppose by keeping all the files open before we get to the second phase). [...] > 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 suppose that's because it needs to determine if the file is a device file or not as for device files where a fs is mounted, it needs to report details for that fs as opposed to the fs the device file is on. -- Stephane From debbugs-submit-bounces@debbugs.gnu.org Mon Oct 30 12:53:10 2017 Received: (at 29038-done) by debbugs.gnu.org; 30 Oct 2017 16:53:10 +0000 Received: from localhost ([127.0.0.1]:42475 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e9DJF-0008P2-RT for submit@debbugs.gnu.org; Mon, 30 Oct 2017 12:53:09 -0400 Received: from mail.magicbluesmoke.com ([82.195.144.49]:44882) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e9DJD-0008Os-H4 for 29038-done@debbugs.gnu.org; Mon, 30 Oct 2017 12:53:07 -0400 Received: from localhost.localdomain (c-73-158-116-184.hsd1.ca.comcast.net [73.158.116.184]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.magicbluesmoke.com (Postfix) with ESMTPSA id 9126A985B; Mon, 30 Oct 2017 16:53:03 +0000 (GMT) Subject: Re: bug#29038: df hangs on fifos/named pipes To: Paul Eggert , Stephane Chazelas , 29038-done@debbugs.gnu.org References: <20171028071811.GA4783@chaz.gmail.com> <0a956ac7-c23d-bad6-09b9-86becfc1b1e0@draigBrady.com> From: =?UTF-8?Q?P=c3=a1draig_Brady?= Message-ID: <056c47f8-0e8f-3350-72a3-ac7eea2b1e1d@draigBrady.com> Date: Mon, 30 Oct 2017 09:53:01 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 29038-done Cc: Martijn Dekker X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) 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... From debbugs-submit-bounces@debbugs.gnu.org Mon Oct 30 13:34:05 2017 Received: (at 29038) by debbugs.gnu.org; 30 Oct 2017 17:34:05 +0000 Received: from localhost ([127.0.0.1]:42517 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e9Dwr-000110-JS for submit@debbugs.gnu.org; Mon, 30 Oct 2017 13:34:05 -0400 Received: from mail-wm0-f46.google.com ([74.125.82.46]:49346) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e9Dwq-00010W-0F for 29038@debbugs.gnu.org; Mon, 30 Oct 2017 13:34:04 -0400 Received: by mail-wm0-f46.google.com with SMTP id b189so17354309wmd.4 for <29038@debbugs.gnu.org>; Mon, 30 Oct 2017 10:34:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=l4UuRAzHtkcpvRNO55aqgQt7SyPJLdP5ExUvaFjB7W0=; b=Gs93YZAyefhKMqASkc/AdiNjV5jMALvTHKOo1PZf/jm6qhN/ZX7aMo/hQWfl8LU0jJ KyMgvSEIruoCWa4+d3VmwELgLATNj1s6YuPH5UoJhsgDDsDQDRZNwr5xX5wNzeLL2fV4 UMsWduqJ9i4usDV5cJWHuTVkmu3i+o9o7R0SVy3u5nzBnvb6x0fqyepeEL6LhZ9HVH1G 2yST4bdGyS9iG2OVXwR2G1znJiop8iuEShhTbG70XG5QTuCn8pZ9w6JIxdb18QlX0gOS IhSOkDAj9CX3otOtiQXsd9nPDFhfTgIzKIIo8vPtVk3GwoLiYfVkyDQtZ4kOATarlcIu r3Mg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=l4UuRAzHtkcpvRNO55aqgQt7SyPJLdP5ExUvaFjB7W0=; b=s1Zu4SgQlL2dBJYNEul0a+KBUO4fx+3EK3dk76+0VQ8J+2aqmDzx2Y7PKHf5Odixv3 dBLsQD46ob8FojY3Jz1sQEhOCKD7flEnt801uoIhjuvHW8oVGY2l30N5xbGP+qffS7O6 iJfc56KlS2kX7hLURN9k/8mVWlXK26g3A5PqcRPT4RTPlBPOFtQCIiEFARA/R5AgRD3q WRm8MbXviJztHDjsdaPudMEbRSEAG6K0psWIqna2ChMfWyfH2IwFalnOlYAqDuZS59ID DC1vbWRQ1oTrw4dAJfa+/qz3mLU9lNm3+EAKEaN2T8ItC5WGV3A4uSmHCHeT4DbAt48c aFjw== X-Gm-Message-State: AMCzsaUnBySZQ4AjI5syiP54+TsNpJppbkON8c/MBS8ngrZcZZt6RQ3d 7XPFWhUdB5zpLnd0hu6HqWE= X-Google-Smtp-Source: ABhQp+Rqc5Gnrr/4X/c+PrF5bY88Hy+j9JiAPJOu+5o/EYR9ee3U+1utgBmNZXZH+4BddV8HggE4CQ== X-Received: by 10.28.126.146 with SMTP id z140mr4865504wmc.126.1509384838234; Mon, 30 Oct 2017 10:33:58 -0700 (PDT) Received: from chaz.gmail.com ([90.198.158.87]) by smtp.gmail.com with ESMTPSA id i1sm8831217wri.34.2017.10.30.10.33.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 30 Oct 2017 10:33:57 -0700 (PDT) Date: Mon, 30 Oct 2017 17:33:56 +0000 From: Stephane Chazelas To: =?iso-8859-1?Q?P=E1draig?= Brady Subject: Re: bug#29038: df hangs on fifos/named pipes Message-ID: <20171030173356.GB24574@chaz.gmail.com> References: <20171028071811.GA4783@chaz.gmail.com> <0a956ac7-c23d-bad6-09b9-86becfc1b1e0@draigBrady.com> <056c47f8-0e8f-3350-72a3-ac7eea2b1e1d@draigBrady.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <056c47f8-0e8f-3350-72a3-ac7eea2b1e1d@draigBrady.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 29038 Cc: 29038@debbugs.gnu.org, Paul Eggert , Martijn Dekker X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.0 (/) 2017-10-30 09:53:01 -0700, Pádraig Brady: [...] > 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. [...] Note that: df /dev/watchdog as root still causes the system to reboot on Linux. Not a POSIX conformance issue as the behaviour is unspecified for device files without a mounted file system on, but still not ideal. The point is that opening files has or can have side effects and df is not *meant* to open files. I would think that automounting directories assuming we do want it to happen should be enough unless someone can come up with a realistic use case where non-directory files are being automounted (and assuming that's possible). -- Stephane From unknown Tue Jun 24 22:35:30 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Tue, 28 Nov 2017 12:24:05 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator