summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJim Meyering <meyering@redhat.com>2009-11-15 09:25:29 +0100
committerJim Meyering <meyering@redhat.com>2009-11-16 09:30:43 +0100
commit3b997a9bcb05198c880e5d1605a3c96c1d7f9c5d (patch)
tree99d9c5b1943e2339986e78e8bfac2c6f506aa424 /src
parent00f0cabaecdd490529d05230435671eb89a7b5c5 (diff)
downloadcoreutils-3b997a9bcb05198c880e5d1605a3c96c1d7f9c5d.tar.xz
tail -F can fail to track a file after it's been rotated
Tailing forever and by-name (--follow=name, -F), tail would sometimes fail to follow a file that had been removed via rename. If you can't apply this patch and have tail 7.6 or newer, you can work around the bug via the undocumented --disable-inotify option. * src/tail.c (tail_forever_inotify): When tailing by name (-F), do not un-watch a file upon receipt of the IN_MOVE_SELF event. Reported by Arjan Opmeer in http://bugs.debian.org/548439. * NEWS (Bug fixes): Mention it. Also see http://marc.info/?l=coreutils-bug&m=125829031916515 * tests/Makefile.am (TESTS): Add tail-2/inotify-rotate. * tests/tail-2/inotify-rotate: New test.
Diffstat (limited to 'src')
-rw-r--r--src/tail.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/tail.c b/src/tail.c
index 09afeec99..9a2f5ae82 100644
--- a/src/tail.c
+++ b/src/tail.c
@@ -1404,7 +1404,13 @@ tail_forever_inotify (int wd, struct File_spec *f, size_t n_files,
if (ev->mask & (IN_ATTRIB | IN_DELETE_SELF | IN_MOVE_SELF))
{
- if (ev->mask & (IN_DELETE_SELF | IN_MOVE_SELF))
+ /* For IN_DELETE_SELF, we always want to remove the watch.
+ However, for IN_MOVE_SELF (the file we're watching has
+ been clobbered via a rename), when tailing by NAME, we
+ must continue to watch the file. It's only when following
+ by file descriptor that we must remove the watch. */
+ if ((ev->mask & IN_DELETE_SELF)
+ || ((ev->mask & IN_MOVE_SELF) && follow_mode == Follow_descriptor))
{
inotify_rm_watch (wd, f[i].wd);
hash_delete (wd_table, &(f[i]));