Jim Meyering wrote: > Pádraig Brady wrote: >> Subject: [PATCH] tail: fix tail -f failure when inotify used >> >> * src/tail.c (tail_inotify_forever): Use the correct bounds >> in the error check of the return from inotify_add_watch(). >> Reported by C de-Avillez. >> --- >> src/tail.c | 2 +- >> 1 files changed, 1 insertions(+), 1 deletions(-) >> >> diff --git a/src/tail.c b/src/tail.c >> index 3c8f425..7d84bec 100644 >> --- a/src/tail.c >> +++ b/src/tail.c >> @@ -1231,7 +1231,7 @@ tail_forever_inotify (int wd, struct File_spec *f, >> size_t n_files, >> if (hash_insert (wd_table, &(f[i])) == NULL) >> xalloc_die (); >> >> - if (follow_mode == Follow_name || f[i].wd) >> + if (follow_mode == Follow_name || 0 <= f[i].wd) > > Ten lines above that, we ensure that 0 <= f[i].wd is true, > so this stmt: > if (follow_mode == Follow_name || 0 <= f[i].wd) > is equivalent to this: > if (follow_mode == Follow_name || true) > aka, > if (true) > > so perhaps that change should be larger: > > - if (follow_mode == Follow_name || f[i].wd) > - found_watchable = true; > + found_watchable = true; > > Also, the initialization (farther above) of f[i].wd to a valid > file descriptor value (0) seems like a mistake: > > - f[i].wd = 0; > + f[i].wd = -1; > > What do you think? >
Agreed. I'll push the attached soon. cheers, Pádraig.
>From 0126b5c9276f9206c8b2c35cd7890267c962ae31 Mon Sep 17 00:00:00 2001 From: =?utf-8?q?P=C3=A1draig=20Brady?= <p...@draigbrady.com> Date: Wed, 12 Aug 2009 19:01:56 +0100 Subject: [PATCH] tail: fix tail -f failure when inotify used * src/tail.c (tail_forever_inotify): Remove the redundant and incorrect error check of the return from inotify_add_watch(). Also initialize the wd member of each File_spec to an invalid value. Reported by C de-Avillez. --- src/tail.c | 5 ++--- 1 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/tail.c b/src/tail.c index 3c8f425..6f83706 100644 --- a/src/tail.c +++ b/src/tail.c @@ -1193,7 +1193,7 @@ tail_forever_inotify (int wd, struct File_spec *f, size_t n_files, if (evlen < fnlen) evlen = fnlen; - f[i].wd = 0; + f[i].wd = -1; if (follow_mode == Follow_name) { @@ -1231,8 +1231,7 @@ tail_forever_inotify (int wd, struct File_spec *f, size_t n_files, if (hash_insert (wd_table, &(f[i])) == NULL) xalloc_die (); - if (follow_mode == Follow_name || f[i].wd) - found_watchable = true; + found_watchable = true; } } -- 1.6.2.5