Bug 10196

Summary: tail -F loses information during log rotation
Product: Busybox Reporter: Jakub Piotr Cłapa <jpc>
Component: OtherAssignee: unassigned
Status: NEW ---    
Severity: normal CC: busybox-cvs
Priority: P5    
Version: 1.23.x   
Target Milestone: ---   
Hardware: All   
OS: Linux   
Host: Target:
Build:

Description Jakub Piotr Cłapa 2017-08-09 14:37:51 UTC
Hi,

I am using svlogd for logging and tail -F current to follow on them. I noticed that sometimes I would miss some lines that were added to the files immediately before they were renamed.

I looked into the code and noticed that (when FOLLOW_RETRY is true) after sleeping tail immediately checks if the file was replaced (the inode changed) before it tries to read and print the remaining bytes. As far as I understand it this means that if the old file was appended to and the renamed it would miss this information.

Have anyone noticed it before? I probably should write a test case for this and think about a patch but I would like to hear a second opinion on this first.
Comment 1 Jan Hudec 2019-08-29 11:37:04 UTC
Hi,

Yes, this is a problem. It basically renders the FOLLOW_RETRY option useless, and subtly useless at that, because following rotated logs is the main purpose of the option.

The file shall be read to the end between checking the inode equality and reopening it.