GNU bug report logs - #19760
[bug] "tail -f" with inotify fails to follow a file after a rename()

Previous Next

Package: coreutils;

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

Date: Tue, 3 Feb 2015 22:05:02 UTC

Severity: normal

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

Bug is archived. No further changes may be made.

Full log


Message #11 received at 19760 <at> debbugs.gnu.org (full text, mbox):

From: Pádraig Brady <P <at> draigBrady.com>
To: Stephane Chazelas <stephane.chazelas <at> gmail.com>, 
 19760 <at> debbugs.gnu.org
Subject: Re: bug#19760: [bug] "tail -f" with inotify fails to follow a file
 after a rename()
Date: Tue, 31 Mar 2015 04:15:27 +0100
[Message part 1 (text/plain, inline)]
On 03/02/15 23:30, Pádraig Brady wrote:
> On 03/02/15 22:04, Stephane Chazelas wrote:
>> Hello,
>>
>> On Linux, when inotify is used,
>>
>>    tail -f file
>>
>> follows a file only until it's renamed. After it is renamed, the
>> inotify watch is removed, which means tail sits there doing
>> nothing and any further modifications to the file are ignored.
>>
>> To reproduce:
>>
>>     echo 1 > file
>>     tail -f file &
>>     exec 3>> file
>>     echo 2 >&3
>>     sleep 1
>>     mv file file2
>>     sleep 1
>>     echo 3 >&3
>>     sleep 1
>>     : > file2
>>
>> "3" is not displayed. No message about the file being truncated
>> either.
>>
>> Work arounds:
>>
>>    tail ---disable-inotify -f file
>>    tail -f < file # effectively disables inotify
>>
>>    or rename the file with a link() followed by an unlink()
>>    ln file newfile && rm -f file
>>
>> Note that the IN_DELETED_SELF event is not reached in
>> follow-descriptor mode because tail has the file open preventing
>> it from being deleted even after it's unlinked from the last
>> directory.
>>
>> Patch attached (on the current git head).
> 
> Ouch. The patch makes sense on first glance,
> and all existing tests pass with it.
> I'll check some more and add a test.

Sorry for the delay.
I'll apply the attached in your name soon.

thanks,
Pádraig.

[tail-rename-desc.patch (text/x-patch, attachment)]

This bug report was last modified 10 years and 56 days ago.

Previous Next


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