]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
tail: exit without reading input if would never output
authorPádraig Brady <P@draigBrady.com>
Tue, 26 Mar 2013 00:36:01 +0000 (00:36 +0000)
committerPádraig Brady <P@draigBrady.com>
Thu, 4 Apr 2013 02:01:48 +0000 (03:01 +0100)
* src/tail.c (main): If -n0 or -c0 were specified without -f,
then no data would ever be output, so exit without reading input.
* tests/tail-2/tail-n0f.sh: Augment the related test with this case.

src/tail.c
tests/tail-2/tail-n0f.sh

index ca851ee6fdfcdaa9ea40171f2e1b100f86787d70..cdaecddc401878108c61c4ffb054d2217633f2cf 100644 (file)
@@ -2149,6 +2149,10 @@ main (int argc, char **argv)
                      " indefinitely is ineffective"));
   }
 
+  /* Don't read anything if we'll never output anything.  */
+  if (! n_units && ! forever && ! from_start)
+    exit (EXIT_SUCCESS);
+
   F = xnmalloc (n_files, sizeof *F);
   for (i = 0; i < n_files; i++)
     F[i].name = file[i];
index a8d37597830a1bdcabfc4af638757b1c7a528966..1c6ba89eb7e40f53a13038a550b863356bd235bd 100755 (executable)
@@ -29,6 +29,11 @@ require_proc_pid_status_
 touch empty || framework_failure_
 echo anything > nonempty || framework_failure_
 
+# First verify that -[nc]0 without -f, exit without reading
+touch unreadable || framework_failure_
+chmod 0 unreadable || framework_failure_
+tail -c0 unreadable || fail=1
+tail -n0 unreadable || fail=1
 
 for inotify in ---disable-inotify ''; do
   for file in empty nonempty; do