GNU bug report logs - #74653
tail --follow=name doesn't exit when using inotify and the file is moved

Previous Next

Package: coreutils;

Reported by: Göran Uddeborg <goeran <at> uddeborg.se>

Date: Mon, 2 Dec 2024 16:20: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: Göran Uddeborg <goeran <at> uddeborg.se>
Subject: bug#74653: closed (Re: bug#74653: tail --follow=name doesn't exit
 when using inotify and the file is moved)
Date: Thu, 05 Dec 2024 12:57:02 +0000
[Message part 1 (text/plain, inline)]
Your bug report

#74653: tail --follow=name doesn't exit when using inotify and the file is moved

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 74653 <at> debbugs.gnu.org.

-- 
74653: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=74653
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: Göran Uddeborg <goeran <at> uddeborg.se>,
 74653-done <at> debbugs.gnu.org
Subject: Re: bug#74653: tail --follow=name doesn't exit when using inotify and
 the file is moved
Date: Thu, 5 Dec 2024 12:55:29 +0000
[Message part 3 (text/plain, inline)]
On 04/12/2024 11:55, Pádraig Brady wrote:
> On 02/12/2024 16:19, Göran Uddeborg wrote:
>> When using "tail --follow=name", but without "--retry", on a file
>> supporting inotify, the command doesn't finish if the file is moved to
>> a new name.
>>
>> Repeat this way on a local filesystem:
>>
>>       echo apa > apa
>>       tail --follow=name apa &
>>       mv apa bepa
>>
>> "tail" will print an error message saying "No such file or directory",
>> but it will continue running. I would expect a following message "no
>> files remaining" and "tail" to exit.
>>
>> If the file system doesn't support inotify, if "apa" is on NFS for
>> example, "tail" exits as expected.
>>
>> If the file is removed rather than moved ("rm apa") "tail" also exits
>> as expected.
>>
>> This is tested on Fedora 41 using
>>
>> coreutils-9.5-11.fc41.x86_64
>> kernel-6.11.6-300.fc41.x86_64
> 
> Yes that is a bug.
> The info docs state this:
> 
> "In that [renamed file] case, use ‘--follow=name’ to track the named file,
>    perhaps by reopening it periodically to see if it has been removed
>    and recreated by some other program.  Note that the inotify-based
>    implementation handles this case without the need for any periodic reopening."
> 
> But that description only alludes to the implementation,
> and not any functional difference I would say.
> I.e. inotify should not imply --retry.
> 
> Interestingly if you `rm depa` before recreating "apa" in the example above,
> then tail does exit.  Also tail will exit immediately if "apa" is not present
> at startup.  Also tail will exit if you move "apa" to a different directory.
> All of those existing behaviors gives us latitude to adjust this behavior I think,
> so that tail does in fact exit for the case above with inotify.
> 
> BTW one can test the non-inotify behavior on any file system
> with the undocumented ---disable-inotify option.

I'll push the attached later to fix this.

Marking this as done.

thanks,
Pádraig
[tail-unfollow-renames.patch (text/x-patch, attachment)]
[Message part 5 (message/rfc822, inline)]
From: Göran Uddeborg <goeran <at> uddeborg.se>
To: bug-coreutils <at> gnu.org
Subject: tail --follow=name doesn't exit when using inotify and the file
 is moved
Date: Mon, 2 Dec 2024 17:19:21 +0100
When using "tail --follow=name", but without "--retry", on a file
supporting inotify, the command doesn't finish if the file is moved to
a new name.

Repeat this way on a local filesystem:

    echo apa > apa
    tail --follow=name apa &
    mv apa bepa

"tail" will print an error message saying "No such file or directory",
but it will continue running. I would expect a following message "no
files remaining" and "tail" to exit.

If the file system doesn't support inotify, if "apa" is on NFS for
example, "tail" exits as expected.

If the file is removed rather than moved ("rm apa") "tail" also exits
as expected.

This is tested on Fedora 41 using

coreutils-9.5-11.fc41.x86_64
kernel-6.11.6-300.fc41.x86_64



This bug report was last modified 166 days ago.

Previous Next


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