GNU bug report logs -
#74653
tail --follow=name doesn't exit when using inotify and the file is moved
Previous Next
Full log
Message #13 received at 74653-done <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (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)]
This bug report was last modified 165 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.