Bug 1006221

Summary: tail -F does not handle dead symlinks gracefully
Product: Red Hat Enterprise Linux 6 Reporter: Pushpendra Chavan <pchavan>
Component: coreutilsAssignee: Ondrej Oprala <ooprala>
Status: CLOSED ERRATA QA Contact: qe-baseos-daemons
Severity: medium Docs Contact:
Priority: medium    
Version: 6.4CC: azelinka, byount, ooprala, ovasik, pbrady, pchavan, pkrizak, todoleza
Target Milestone: rc   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: coreutils-8.4-28.el6 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
: 1035219 (view as bug list) Environment:
Last Closed: 2013-11-21 20:57:02 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 1035219    

Description Pushpendra Chavan 2013-09-10 09:17:25 UTC
Description of problem:
The version of 'tail' that ships with RHEL6.4 appears to be mishandling dead symlinks. 

Version-Release number of selected component (if applicable):
coreutils-8.4-19.el6.x86_64

How reproducible:
Always

Steps to Reproduce:
Please follow these precise steps in order to reproduce the errant behavior.  I've prefixed each command with T1 or T2, to indicate whether that command should be run in the first terminal (T1) or the second (T2).  The commands should be run in this precise order.

T1: touch logfile
T1: ln -s logfile logfile-link
T2: tail -F logfile-link
T1: echo "line 1" >> logfile
T2: observe "line 1" from tail
T1: rm logfile
T2: observe "tail: `logfile-link' has become inaccessible: No such file or directory"
T1: echo "line 2" >> logfile
T2: observe that tail is no longer tracking the contents of 'logfile'

Here is the terminal demonstration.

~~~~~~~~~~~~~~~~~~~~~
On Red Hat Enterprise Linux 5:
~~~~~~~~~~~~~~~~~~~~~

Terminal#1:

[root@dhcp223-183 ~]# mkdir /tmp/test
[root@dhcp223-183 ~]# cd /tmp/test
[root@dhcp223-183 test]# touch logfile
[root@dhcp223-183 test]# 
[root@dhcp223-183 test]# ln -s logfile logfile-link
[root@dhcp223-183 test]# echo "line 1" >> logfile
[root@dhcp223-183 test]# rm -rf logfile
[root@dhcp223-183 test]# echo "line 2" >> logfile

Terminal#2:

[root@dhcp223-183 ~]# cd /tmp/test/
[root@dhcp223-183 test]# tail -F logfile-link 
line 1
tail: `logfile-link' has become inaccessible: No such file or directory
line 2

It started appending the new lines.

~~~~~~~~~~~~~~~~~~~~~
Whereas on Red Hat Enterprise Linux 6:
~~~~~~~~~~~~~~~~~~~~~

Terminal#1:

[root@dhcp223-116 ~]# mkdir /tmp/test
[root@dhcp223-116 ~]# cd /tmp/test
[root@dhcp223-116 test]# touch logfile
[root@dhcp223-116 test]# ln -s logfile logfile-link
[root@dhcp223-116 test]# echo "line 1" >> logfile
[root@dhcp223-116 test]# rm logfile
rm: remove regular file `logfile'? y
[root@dhcp223-116 test]# echo "line 2" >> logfile
[root@dhcp223-116 test]# ls
logfile  logfile-link
[root@dhcp223-116 test]# echo "line 2" >> logfile
[root@dhcp223-116 test]# ll
total 4
-rw-r--r-- 1 root root 14 Sep  6 10:53 logfile
lrwxrwxrwx 1 root root  7 Sep  6 10:47 logfile-link -> logfile

Terminal#2:

[root@dhcp223-116 ~]# cd /tmp/test
[root@dhcp223-116 test]# tail -F logfile-link
line 1
tail: `logfile-link' has become inaccessible: No such file or directory


^C

Here the new incoming text was not appended in tail -F output on terminal 2.


Actual results:
Tail should notice when it's monitoring a dead symlink, and "wake up" when the symlink is no longer dead, and monitor the referent's content.

Expected results:
Its not monitoring it.

Additional info:
This works on Red Hat Enterprise Linux 5 as expected.

Comment 2 Paul Krizak 2013-09-10 16:23:30 UTC
(In reply to Pushpendra Chavan from comment #0)

> Actual results:
> Tail should notice when it's monitoring a dead symlink, and "wake up" when
> the symlink is no longer dead, and monitor the referent's content.
> 
> Expected results:
> Its not monitoring it.

The expected and actual results are backwards.  The actual result (in RHEL6) is that tail -F ignores updates to the referent of a symlink after the symlink is killed (the referent is removed).  The expected results are like in RHEL5: tail notices when the dead symlink is revived and resumes tailing the contents of the referent.

Comment 3 Ondrej Vasik 2013-09-11 11:09:32 UTC
The difference is that RHEL-6 is using inotify and RHEL-5 is using polling. You can kind of restore the RHEL-5 behaviour with using ---disable-inotify (intentionally undocumented option, as polling mode is considered deprecated). Still probably worth to fix in tail.
Issue still occurs even with coreutils-8.21.

Comment 9 errata-xmlrpc 2013-11-21 20:57:02 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

http://rhn.redhat.com/errata/RHSA-2013-1652.html

Comment 10 Pádraig Brady 2014-09-04 11:50:18 UTC
Note the fix for this is too noisy, reporting the following "error" for any symlinks:
  https://www.centos.org/forums/viewtopic.php?f=14&t=48255

The upstream fix silently reverted to polling:
  http://git.sv.gnu.org/gitweb/?p=coreutils.git;a=commitdiff;h=ba6582e

Comment 14 Pádraig Brady 2014-10-14 09:16:54 UTC
This is now public: https://bugzilla.redhat.com/show_bug.cgi?id=1006221#c10
Basically the downstream fix for that was too noisy.
Upstream doesn't bleat about this implementation detail.