From cdfb703c5da31a798557722df516e0d01dac828a Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Mon, 7 Sep 2009 08:37:08 +0200 Subject: 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 . * 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". --- src/tail.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'src/tail.c') diff --git a/src/tail.c b/src/tail.c index e3b9529f8..c53df9e3f 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) -- cgit v1.2.3-54-g00ecf