Hi Jim,
Jim Meyering <[email protected]> writes: > However, while looking at it, I discovered another problem. > When tail-F'd files may be renamed, tail may fail to track > the target of a rename. good catch and very useful test case! I am going to like the test driven development we we had today :-) This patch should fix the problem, other tests remain green. >From f108dc01f86fb8df057172d2bafd8224759be884 Mon Sep 17 00:00:00 2001 From: Giuseppe Scrivano <[email protected]> Date: Wed, 30 Dec 2009 00:20:24 +0100 Subject: [PATCH] tail: ensure the wd is not already present in the hash table before add it * src/tail.c (tail_forever_inotify): When a new watch descriptor is added to the `wd_to_name' hash table, check that it is not already present. If it is present then remove the previous element. --- src/tail.c | 15 ++++++++++++++- 1 files changed, 14 insertions(+), 1 deletions(-) diff --git a/src/tail.c b/src/tail.c index 3d5e221..28a0e26 100644 --- a/src/tail.c +++ b/src/tail.c @@ -1486,11 +1486,24 @@ tail_forever_inotify (int wd, struct File_spec *f, size_t n_files, /* Remove `fspec' and re-add it using `new_fd' as its key. */ hash_delete (wd_to_name, fspec); fspec->wd = new_wd; + + /* If the file was moved then inotify will use the source file wd for + the destination file. Make sure the key is not present in the + table. */ + struct File_spec *prev = hash_delete (wd_to_name, fspec); + if (prev && prev != fspec) + { + if (follow_mode == Follow_name) + recheck (prev, false); + prev->wd = -1; + close_fd (prev->fd, pretty_name (prev)); + } + if (hash_insert (wd_to_name, fspec) == NULL) xalloc_die (); if (follow_mode == Follow_name) - recheck (&(f[j]), false); + recheck (fspec, false); } else { -- 1.6.5 > Here's a similar test that fails with inotify-enabled tail, > yet passes with ---disable-inotify: > > +debug='---disable-inotify -s .01' > +debug= What do you think about run the test in both modes? Cheers, Giuseppe
