bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: tail aborts while following by name if using inotify


From: Giuseppe Scrivano
Subject: Re: tail aborts while following by name if using inotify
Date: Tue, 29 Dec 2009 15:33:19 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1.90 (gnu/linux)

Hello Jim,

Jim Meyering <address@hidden> writes:

> Rob Wortman wrote:
>> I have noticed a behavioral quirk in versions of tail which use inotify.
>> When following a file by name (using tail -F or tail --follow=name),
>> tail will abort when a file returns after being renamed. I see that this
>> bug was addressed in coreutils-8.1, but I still find the behavior in
>> coreutils-8.2.
>
> Here's a first step: add a test to exercise the losing code.
> The final "cat out" isn't required, but I found it handy while
> writing the test, so left it in.

this patch makes your test case pass successfully.  It must be applied
after the three patches you have sent in another thread.


Cheers,
Giuseppe



>From e249f9ab639d318d709eed722b57bc232a7657c1 Mon Sep 17 00:00:00 2001
From: Giuseppe Scrivano <address@hidden>
Date: Tue, 29 Dec 2009 14:59:24 +0100
Subject: [PATCH] tail: remove `fdspec' from the hash table before change its key

* src/tail.c (tail_forever_inotify): Avoid to modify fdspec->wd until it
is contained in the wd_to_name hash table with a different key value.
Once it is removed, it can be added using the new `wd' as key for the
hash table.
---
 src/tail.c |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/src/tail.c b/src/tail.c
index 8e6c8ac..83b4253 100644
--- a/src/tail.c
+++ b/src/tail.c
@@ -1474,15 +1474,18 @@ tail_forever_inotify (int wd, struct File_spec *f, 
size_t n_files,
             continue;
 
           /* It's fine to add the same file more than once.  */
-          f[j].wd = inotify_add_watch (wd, f[j].name, inotify_wd_mask);
-
-          if (f[j].wd < 0)
+          int new_wd = inotify_add_watch (wd, f[j].name, inotify_wd_mask);
+          if (new_wd < 0)
             {
               error (0, errno, _("cannot watch %s"), quote (f[j].name));
               continue;
             }
 
           fspec = &(f[j]);
+
+          /* Remove `fspec' and re-add it using `new_fd' as its key.  */
+          hash_delete (wd_to_name, fspec);
+          f[j].wd = new_wd;
           if (hash_insert (wd_to_name, fspec) == NULL)
             xalloc_die ();
 
-- 
1.6.5.7




reply via email to

[Prev in Thread] Current Thread [Next in Thread]