>From f97355fa31f5e13f95667a50908506388d62df64 Mon Sep 17 00:00:00 2001 From: Stephane Chazelas Date: Tue, 3 Feb 2015 21:22:06 +0000 Subject: [PATCH] tail: fix rename in follow-descriptor mode In follow-descriptor mode, even when using inotify, we don't care if the file has been renamed or deleted. We still want to watch it. --- src/tail.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/tail.c b/src/tail.c index b512c2a..864c71f 100644 --- a/src/tail.c +++ b/src/tail.c @@ -159,13 +159,6 @@ struct File_spec uintmax_t n_unchanged_stats; }; -#if HAVE_INOTIFY -/* The events mask used with inotify on files. This mask is not used on - directories. */ -static const uint32_t inotify_wd_mask = (IN_MODIFY | IN_ATTRIB - | IN_DELETE_SELF | IN_MOVE_SELF); -#endif - /* Keep trying to open a file even if it is inaccessible when tail starts or if it becomes inaccessible later -- useful only with -f. */ static bool reopen_inaccessible_files; @@ -1385,11 +1378,22 @@ tail_forever_inotify (int wd, struct File_spec *f, size_t n_files, char *evbuf; size_t evbuf_off = 0; size_t len = 0; + uint32_t inotify_wd_mask; wd_to_name = hash_initialize (n_files, NULL, wd_hasher, wd_comparator, NULL); if (! wd_to_name) xalloc_die (); + /* The events mask used with inotify on files. This mask is not used on + directories. */ + if (follow_mode == Follow_name) + inotify_wd_mask = (IN_MODIFY | IN_ATTRIB | IN_DELETE_SELF | IN_MOVE_SELF); + else + /* if following by descriptor, we're watching the same file even if + unlinked or renamed. */ + inotify_wd_mask = IN_MODIFY; + + /* Add an inotify watch for each watched file. If -F is specified then watch its parent directory too, in this way when they re-appear we can add them again to the watch list. */ -- 1.9.1