bug-coreutils
[Top][All Lists]
Advanced

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

Re: [PATCH] tail: add comments noting potential inotify-related problems


From: Giuseppe Scrivano
Subject: Re: [PATCH] tail: add comments noting potential inotify-related problems
Date: Fri, 03 Jul 2009 00:06:39 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.95 (gnu/linux)

Hi Jim,

I took a look at the problems you reported.  The first one is fixed with
the first attached patch.

I have tested it under Linux 2.6.18-6-xen-686.


tail -F works until the parent directory is not removed and it is very
related to the second problem you showed.  At this point I think the
best way is to find a solution to both, using a tree instead of a hash
map.  What do you think?

Thanks,
Giuseppe


Jim Meyering <address@hidden> writes:

> Hi Giuseppe,
>
> I noticed two potential problems.
> The first appears to affects only kernels 2.6.13..2.6.20.
> The second one doesn't have to be fixed before the upcoming release.


>From 8fbe1d2d1f666a0428f41d03831e18d4d1b56e89 Mon Sep 17 00:00:00 2001
From: Giuseppe Scrivano <address@hidden>
Date: Thu, 2 Jul 2009 23:38:46 +0200
Subject: [PATCH 1/2] tail: avoid a problem for kernels prior to 2.6.21

* src/tail.c (tail_forever_inotify): Handle the special case that the
inotify watcher returns zero bytes.
---
 src/tail.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/tail.c b/src/tail.c
index 89c43b8..a99091a 100644
--- a/src/tail.c
+++ b/src/tail.c
@@ -1259,8 +1259,9 @@ tail_forever_inotify (int wd, struct File_spec *f, int 
n_files)
           evbuf_off = 0;
 
           /* For kernels prior to 2.6.21, read returns 0 when the buffer
-             is too small.  FIXME: handle that.  */
-          if (len == SAFE_READ_ERROR && errno == EINVAL && max_realloc--)
+             is too small.  */
+          if ((len == 0 || (len == SAFE_READ_ERROR && errno == EINVAL)) &&
+             max_realloc--)
             {
               len = 0;
               evlen *= 2;
@@ -1268,7 +1269,7 @@ tail_forever_inotify (int wd, struct File_spec *f, int 
n_files)
               continue;
             }
 
-          if (len == SAFE_READ_ERROR)
+          if (len == SAFE_READ_ERROR || len == 0)
             error (EXIT_FAILURE, errno, _("error reading inotify event"));
         }
 
-- 
1.6.3.3


>From bfbd6a82055326ea45882664890a5e77aa3bb2a1 Mon Sep 17 00:00:00 2001
From: Giuseppe Scrivano <address@hidden>
Date: Thu, 2 Jul 2009 23:40:40 +0200
Subject: [PATCH 2/2] tail: fixed a test case

* tests/tail-2/wait: Be sure the `not_accessible' file is really not
accessible before try to "tail -f" it.
---
 tests/tail-2/wait |   23 +++++++++++++----------
 1 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/tests/tail-2/wait b/tests/tail-2/wait
index 7eee8b1..8f2f610 100755
--- a/tests/tail-2/wait
+++ b/tests/tail-2/wait
@@ -45,17 +45,20 @@ if test -n "$state"; then
   kill $pid
 fi
 
-tail -s0.1 -f not_accessible &
-pid=$!
-sleep .5
-state=$(get_process_status_ $pid)
-
-if test -n "$state"; then
-  case $state in
-    S*) echo $0: process still active 1>&2; fail=1 ;;
-    *) ;;
-  esac
-  kill $pid
+# Check if the file is really not accessible before use it.
+if ! cat not_accessible; then
+    tail -s0.1 -f not_accessible &
+    pid=$!
+    sleep .5
+    state=$(get_process_status_ $pid)
+
+    if test -n "$state"; then
+        case $state in
+            S*) echo $0: process still active 1>&2; fail=1 ;;
+            *) ;;
+        esac
+        kill $pid
+    fi
 fi
 
 (tail -s0.1 -f here 2>tail.err) &
-- 
1.6.3.3




reply via email to

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