GNU bug report logs - #19765
tail -F stops watching when read permissions are removed

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: coreutils; Severity: wishlist; Reported by: Stephane Chazelas <stephane.chazelas@HIDDEN>; dated Wed, 4 Feb 2015 10:23:01 UTC; Maintainer for coreutils is bug-coreutils@HIDDEN.
Severity set to 'wishlist' from 'normal' Request was from Assaf Gordon <assafgordon@HIDDEN> to control <at> debbugs.gnu.org. Full text available.

Message received at 19765 <at> debbugs.gnu.org:


Received: (at 19765) by debbugs.gnu.org; 5 Feb 2015 13:07:58 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Feb 05 08:07:58 2015
Received: from localhost ([127.0.0.1]:34583 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1YJMA1-00068H-NS
	for submit <at> debbugs.gnu.org; Thu, 05 Feb 2015 08:07:58 -0500
Received: from mail2.vodafone.ie ([213.233.128.44]:59413)
 by debbugs.gnu.org with esmtp (Exim 4.80)
 (envelope-from <P@HIDDEN>) id 1YJM9y-000681-RI
 for 19765 <at> debbugs.gnu.org; Thu, 05 Feb 2015 08:07:55 -0500
X-IronPort-Anti-Spam-Filtered: true
X-IronPort-Anti-Spam-Result: AmoFAChq01RtTD0E/2dsb2JhbABagwaDXU/CbYJPAoElQwEBAQEBfYQNAQUjDwFWCw0LAgIFFgsCAgkDAgECAUUGAQwIAQGILQG/U4VpkEkBCyCBIY5egmiBQQWZVYEhhB0LjAoig24+gnMBAQE
Received: from unknown (HELO localhost.localdomain) ([109.76.61.4])
 by mail2.vodafone.ie with ESMTP; 05 Feb 2015 13:07:47 +0000
Message-ID: <54D36B22.6080803@HIDDEN>
Date: Thu, 05 Feb 2015 13:07:46 +0000
From: =?UTF-8?B?UMOhZHJhaWcgQnJhZHk=?= <P@HIDDEN>
User-Agent: Mozilla/5.0 (X11; Linux x86_64;
 rv:31.0) Gecko/20100101 Thunderbird/31.4.0
MIME-Version: 1.0
To: Stephane Chazelas <stephane.chazelas@HIDDEN>, 
 19765 <at> debbugs.gnu.org
Subject: Re: bug#19765: tail -F stops watching when read permissions are
 removed
References: <20150204102211.GB6648@HIDDEN>
In-Reply-To: <20150204102211.GB6648@HIDDEN>
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 19765
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: 0.0 (/)

On 04/02/15 10:22, Stephane Chazelas wrote:
> When watchnig a file by name with "tail -F", if read permissions
> are removed, tail stops watching even though it has a file
> descriptor open on the file.
> 
> With inotify:
> 
> $ : > file
> $ tail -F file &
> [1] 20796
> $ exec 3>> file
> $ echo 1 >&3
> 1
> $ chmod 0 file
> tail: %                                                                                                                                                        cannot watch ‘file’: Permission denied
> tail: ‘file’ has become inaccessible: Permission denied
> $ echo 2 >&3  ## not detected at this point
> $ chmod +r file
> tail: ‘file’ has become accessible
> # new content not displayed yet.
> $ echo 3 >&3
> 1   ## all lines displayed
> 2
> 3
> 
> Without inotify:
> 
> $ : > file
> $ tail -F ---disable-inotify file &
> [1] 20903
> $ exec 3>> file
> $ echo 1 >&3
> 1
> $ chmod 0 file
> $ echo 2 >&3
> 2  # not detected yet
> $ tail: ‘file’ has become inaccessible: Permission denied
> 
> $ echo 3 >&3
> $ chmod +r file
> $ tail: ‘file’ has become accessible
> 1
> 2
> 3
> 
> (same except there's a delay before tail detects the file is no longer
> readable).
> 
> Note that the file in that case is still accessible, one can
> still do a stat() on it to check that the file is still the same
> one. That's different from when one of the directory components
> becomes unreadable/unsearchable, in which case tail can't tell
> if it's still reading the right file as in:
> 
>    tail -F foo/bar &
>    chmod 0 foo
> 
> There, tail still has an open file descriptor to foo/bar, but
> can't tell if it still points to the "foo/bar" file, so it's
> acceptable for it to stop watching in that case.
> 
> With inotify though, it doesn't unless the file attributes are
> changed (chmod...) or the file is renamed. I think I'll raise a
> separate bug report for that and directory components being
> renamed.
> 
> [tested with git head]
> 

Handling of files that only change perms is awkward.
In the inotify case we don't close the associated watch descriptor
so continue to process events, though ignore them as we've closed the file.

Another problem in this situation with inotify is that write events between
the chmod a-r and a+r are lost, thus not outputting new data until
the next write event.

Another larger problem in this situation with and without inotify
is that the whole file is output, when tail outputs next.
That's documented as a FIXME-maybe in the code.

thanks,
Pádraig.




Information forwarded to bug-coreutils@HIDDEN:
bug#19765; Package coreutils. Full text available.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 4 Feb 2015 10:22:26 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Wed Feb 04 05:22:26 2015
Received: from localhost ([127.0.0.1]:33443 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1YIx6I-0001k1-8f
	for submit <at> debbugs.gnu.org; Wed, 04 Feb 2015 05:22:26 -0500
Received: from eggs.gnu.org ([208.118.235.92]:35958)
 by debbugs.gnu.org with esmtp (Exim 4.80)
 (envelope-from <stephane.chazelas@HIDDEN>) id 1YIx6G-0001jp-Tp
 for submit <at> debbugs.gnu.org; Wed, 04 Feb 2015 05:22:25 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <stephane.chazelas@HIDDEN>) id 1YIx6A-00020J-TZ
 for submit <at> debbugs.gnu.org; Wed, 04 Feb 2015 05:22:19 -0500
X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org
X-Spam-Level: 
X-Spam-Status: No, score=-0.5 required=5.0 tests=BAYES_05,FREEMAIL_FROM,
 T_DKIM_INVALID autolearn=disabled version=3.3.2
Received: from lists.gnu.org ([2001:4830:134:3::11]:49932)
 by eggs.gnu.org with esmtp (Exim 4.71)
 (envelope-from <stephane.chazelas@HIDDEN>) id 1YIx6A-0001zr-Qv
 for submit <at> debbugs.gnu.org; Wed, 04 Feb 2015 05:22:18 -0500
Received: from eggs.gnu.org ([2001:4830:134:3::10]:37673)
 by lists.gnu.org with esmtp (Exim 4.71)
 (envelope-from <stephane.chazelas@HIDDEN>) id 1YIx69-00062z-BY
 for bug-coreutils@HIDDEN; Wed, 04 Feb 2015 05:22:18 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <stephane.chazelas@HIDDEN>) id 1YIx66-0001pT-5T
 for bug-coreutils@HIDDEN; Wed, 04 Feb 2015 05:22:17 -0500
Received: from mail-we0-x22d.google.com ([2a00:1450:400c:c03::22d]:53454)
 by eggs.gnu.org with esmtp (Exim 4.71)
 (envelope-from <stephane.chazelas@HIDDEN>) id 1YIx65-0001o6-T6
 for bug-coreutils@HIDDEN; Wed, 04 Feb 2015 05:22:14 -0500
Received: by mail-we0-f173.google.com with SMTP id w62so840059wes.4
 for <bug-coreutils@HIDDEN>; Wed, 04 Feb 2015 02:22:13 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;
 h=date:from:to:subject:message-id:mime-version:content-type
 :content-disposition:content-transfer-encoding:user-agent;
 bh=wkhz79CxpPoYaU0UZxeu7ssoP0sZkopoi/kx9Ydd9fc=;
 b=wAXp5pL9mhwxPKDUPV+uzjGMf/g04n7vdO394CRmeWVQW4Ia9x8m8kBg8Rqsi3wNIT
 4KbQI4j/0BedI37BwNqOp8QBhcolUJsgz0DGbzl6IQlxyIBtyIZhABg4dcEkP3nJ/uGB
 d9uOu883qADEjqO2lfyW5jNsfmtiub8wmMPzON3e43jYjfPoQTAy3XTvzG6HlqHFBRG4
 lFlsOp9lLlIQIZ12ZsiWfpr2BnosX8XSKZ6W4b2ta4NCNarvzGnPYi2TkI6mb6hk7ASA
 TxxnyTtdTcUWvtX8upBsREypx8PNBi4KtQntmy44Hqu9xbGhtzcAXnZRARzpbVxo3Ubj
 hd6A==
X-Received: by 10.180.37.197 with SMTP id a5mr43784955wik.2.1423045333206;
 Wed, 04 Feb 2015 02:22:13 -0800 (PST)
Received: from chaz.gmail.com (5ec33bc9.skybroadband.com. [94.195.59.201])
 by mx.google.com with ESMTPSA id eb10sm2539515wib.13.2015.02.04.02.22.12
 for <bug-coreutils@HIDDEN>
 (version=TLSv1.2 cipher=RC4-SHA bits=128/128);
 Wed, 04 Feb 2015 02:22:12 -0800 (PST)
Date: Wed, 4 Feb 2015 10:22:11 +0000
From: Stephane Chazelas <stephane.chazelas@HIDDEN>
To: bug-coreutils@HIDDEN
Subject: tail -F stops watching when read permissions are removed
Message-ID: <20150204102211.GB6648@HIDDEN>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Disposition: inline
Content-Transfer-Encoding: 8bit
User-Agent: Mutt/1.5.21 (2010-09-15)
X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address
 (bad octet value).
X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address
 (bad octet value).
X-Received-From: 2001:4830:134:3::11
X-Spam-Score: -4.0 (----)
X-Debbugs-Envelope-To: submit
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -4.0 (----)

When watchnig a file by name with "tail -F", if read permissions
are removed, tail stops watching even though it has a file
descriptor open on the file.

With inotify:

$ : > file
$ tail -F file &
[1] 20796
$ exec 3>> file
$ echo 1 >&3
1
$ chmod 0 file
tail: %                                                                                                                                                        cannot watch ‘file’: Permission denied
tail: ‘file’ has become inaccessible: Permission denied
$ echo 2 >&3  ## not detected at this point
$ chmod +r file
tail: ‘file’ has become accessible
# new content not displayed yet.
$ echo 3 >&3
1   ## all lines displayed
2
3

Without inotify:

$ : > file
$ tail -F ---disable-inotify file &
[1] 20903
$ exec 3>> file
$ echo 1 >&3
1
$ chmod 0 file
$ echo 2 >&3
2  # not detected yet
$ tail: ‘file’ has become inaccessible: Permission denied

$ echo 3 >&3
$ chmod +r file
$ tail: ‘file’ has become accessible
1
2
3

(same except there's a delay before tail detects the file is no longer
readable).

Note that the file in that case is still accessible, one can
still do a stat() on it to check that the file is still the same
one. That's different from when one of the directory components
becomes unreadable/unsearchable, in which case tail can't tell
if it's still reading the right file as in:

   tail -F foo/bar &
   chmod 0 foo

There, tail still has an open file descriptor to foo/bar, but
can't tell if it still points to the "foo/bar" file, so it's
acceptable for it to stop watching in that case.

With inotify though, it doesn't unless the file attributes are
changed (chmod...) or the file is renamed. I think I'll raise a
separate bug report for that and directory components being
renamed.

[tested with git head]

-- 
Stephane




Acknowledgement sent to Stephane Chazelas <stephane.chazelas@HIDDEN>:
New bug report received and forwarded. Copy sent to bug-coreutils@HIDDEN. Full text available.
Report forwarded to bug-coreutils@HIDDEN:
bug#19765; Package coreutils. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Tue, 23 Oct 2018 02:00:02 UTC

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