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: Jim Meyering
Subject: Re: Bug#545422: coreutils: "tail -f -" fails
Date: Mon, 07 Sep 2009 08:39:00 +0200

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]