[Top][All Lists]
[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 12:53:24 +0200 |
Giuseppe Scrivano wrote:
> 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.
I considered that and discussed the
trade-off in the comment I committed.
There have been systems and configurations with
nonexistent and unusable /dev/stdin files.
commit cdfb703c5da31a798557722df516e0d01dac828a
Author: Jim Meyering <address@hidden>
Date: Mon Sep 7 08:37:08 2009 +0200
tail -f: handle "-"/stdin once again
* src/tail.c (main) [HAVE_INOTIFY]: When stdin (i.e., "-", or no args,
but not /dev/stdin) is specified on the command line, don't use inotify.
Reported by Bill Brelsford in <http://bugs.debian.org/545422>.
* tests/tail-2/follow-stdin: New file. Test for this.
* tests/Makefile.am (TESTS): Add the test.
* 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".
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)