Red Hat Bugzilla – Bug 1006221
tail -F does not handle dead symlinks gracefully
Last modified: 2014-10-14 05:16:54 EDT
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.
(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.
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.
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
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
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.