bug-coreutils
[Top][All Lists]
Advanced

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

Re: Bug#545422: coreutils: "tail -f -" fails


From: Giuseppe Scrivano
Subject: Re: Bug#545422: coreutils: "tail -f -" fails
Date: Mon, 07 Sep 2009 12:34:53 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1.50 (gnu/linux)

Hi Jim,

what do you think about the following solution?  It avoids to revert to
the "old" polling mechanism using "/dev/stdin" instead of "-" to
inotify_add_watch.

Cheers,
Giuseppe


diff --git a/src/tail.c b/src/tail.c
index e3b9529..016b712 100644
--- a/src/tail.c
+++ b/src/tail.c
@@ -1152,6 +1152,12 @@ tail_forever (struct File_spec *f, size_t n_files, 
double sleep_interval)
 
 #if HAVE_INOTIFY
 
+static char const *
+map_inotify_fname (char const *name)
+{
+  return STREQ (name, "-") ? "/dev/stdin" : name;
+}
+
 static size_t
 wd_hasher (const void *entry, size_t tabsize)
 {
@@ -1226,7 +1232,8 @@ tail_forever_inotify (int wd, struct File_spec *f, size_t 
n_files,
                 }
             }
 
-          f[i].wd = inotify_add_watch (wd, f[i].name, inotify_wd_mask);
+          f[i].wd = inotify_add_watch (wd, map_inotify_fname (f[i].name),
+                                      inotify_wd_mask);
 
           if (f[i].wd < 0)
             {
@@ -1330,7 +1337,8 @@ tail_forever_inotify (int wd, struct File_spec *f, size_t 
n_files,
           if (i == n_files)
             continue;
 
-          f[i].wd = inotify_add_watch (wd, f[i].name, inotify_wd_mask);
+          f[i].wd = inotify_add_watch (wd, map_inotify_fname (f[i].name),
+                                      inotify_wd_mask);
 
           if (f[i].wd < 0)
             {




Jim Meyering <address@hidden> writes:

> Bill Brelsford wrote:
>> Package: coreutils
>> Version: 7.5-3
>> Severity: normal
>>
>> "tail -f" no longer works with stdin.  E.g. commands such as
>>
>>      somecommand | tail -f -
>>      somecommand | tail -f
>>      tail -f </var/log/kern
>>
>> fail with the message:
>>
>>      tail: cannot watch `-': No such file or directory
>>
>> Worked under 7.4-2 and previous versions.
>
> Thanks for the report.
> I'm fixing it like this, upstream.
> Test coming momentarily.
>
> From 30269c9ca38c06b31a7c764c192562e3b0268725 Mon Sep 17 00:00:00 2001
> From: Jim Meyering <address@hidden>
> Date: Mon, 7 Sep 2009 08:37:08 +0200
> Subject: [PATCH] tail -f: work on "-" once again
>
> * src/tail.c (main) [HAVE_INOTIFY]: When stdin (i.e., "-", but not
> /dev/stdin) is specified on the command line, don't use inotify.
> Reported by  Bill Brelsford in <http://bugs.debian.org/545422>.
> * NEWS (Bug fixes): Mention it.
> This bug was introduced in coreutils-7.5 via commit ae494d4b,
> 2009-06-02, "tail: use inotify if it is available".
> ---
>  NEWS       |    9 +++++++++
>  src/tail.c |   14 +++++++++++++-
>  2 files changed, 22 insertions(+), 1 deletions(-)
>
> diff --git a/NEWS b/NEWS
> index b02d2da..5c7fb82 100644
> --- a/NEWS
> +++ b/NEWS
> @@ -31,6 +31,15 @@ GNU coreutils NEWS                                    -*- 
> outline -*-
>    Before, this would print nothing and wait: stdbuf -o 4K tail -f /etc/passwd
>    Note that this bug affects tail -f only when its standard output is 
> buffered,
>    which is relatively unusual.
> +  [bug introduced in coreutils-7.5]
> +
> +  tail -f once again works with standard input.  inotify-enabled tail -f
> +  would fail when operating on a nameless stdin.  I.e., tail -f < /etc/passwd
> +  would say "tail: cannot watch `-': No such file or directory", yet the
> +  relatively baroque tail -f /dev/stdin < /etc/passwd would work.  Now, the
> +  offending usage causes tail to revert to its conventional sleep-based
> +  (i.e., not inotify-based) implementation.
> +  [bug introduced in coreutils-7.5]
>
>  ** New features
>
> diff --git a/src/tail.c b/src/tail.c
> index e3b9529..c53df9e 100644
> --- a/src/tail.c
> +++ b/src/tail.c
> @@ -1982,7 +1982,19 @@ main (int argc, char **argv)
>    if (forever)
>      {
>  #if HAVE_INOTIFY
> -      if (!disable_inotify)
> +      /* If the user specifies stdin via a command line argument of "-",
> +         or implicitly by providing no arguments, we won't use inotify.
> +         Technically, on systems with a working /dev/stdin, we *could*,
> +         but would it be worth it?  Verifying that it's a real device
> +         and hooked up to stdin is not trivial, while reverting to
> +         non-inotify-based tail_forever is easy and portable.  */
> +      bool stdin_cmdline_arg = false;
> +
> +      for (i = 0; i < n_files; i++)
> +        if (STREQ (file[i], "-"))
> +          stdin_cmdline_arg = true;
> +
> +      if (!disable_inotify && !stdin_cmdline_arg)
>          {
>            int wd = inotify_init ();
>            if (wd < 0)
> --
> 1.6.4.2.419.gab238




reply via email to

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