From: Pádraig Brady
Date: Tue, 26 Mar 2013 00:36:01 +0000 (+0000) Subject: tail: exit without reading input if would never output X-Git-Tag: v8.22~167 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7abf99e1907b1b05cb45eacaa98bfa73efe0ab92;p=thirdparty%2Fcoreutils.git tail: exit without reading input if would never output * 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. --- diff --git a/src/tail.c b/src/tail.c index ca851ee6fd..cdaecddc40 100644 --- a/src/tail.c +++ b/src/tail.c @@ -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]; diff --git a/tests/tail-2/tail-n0f.sh b/tests/tail-2/tail-n0f.sh index a8d3759783..1c6ba89eb7 100755 --- a/tests/tail-2/tail-n0f.sh +++ b/tests/tail-2/tail-n0f.sh @@ -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