From 3b997a9bcb05198c880e5d1605a3c96c1d7f9c5d Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Sun, 15 Nov 2009 09:25:29 +0100 Subject: 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. --- src/tail.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src') 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])); -- cgit v1.2.3-54-g00ecf