Skip to content

Commit

Permalink
tail: with -f don't warn if doing a blocking read of a tty
Browse files Browse the repository at this point in the history
* src/tail.c: (main): Only issue the warning about -f being
ineffective when we're not going into simple blocking mode.
* tests/tail-2/follow-stdin.sh: Ensure the warning is output correctly.
Fixes http://bugs.gnu.org/27368
  • Loading branch information
pixelb committed Jun 17, 2017
1 parent ce0415f commit aab875a
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 7 deletions.
8 changes: 6 additions & 2 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ GNU coreutils NEWS -*- outline -*-
tail -F 'dir/file' is now monitored even when 'dir' is replaced.
[bug introduced with inotify support added in coreutils-7.5]

tail -f with --pid=PID will now process all inotify events.
tail -f with --pid=PID now processes all inotify events.
Previously events may have been ignored completely upon PID death,
or ignored until future events on the monitored files.
[bug introduced with inotify support added in coreutils-7.5]
Expand All @@ -53,9 +53,13 @@ GNU coreutils NEWS -*- outline -*-

mv --verbose now distinguishes rename and copy operations.

tail -f will now exit immediately if the output is piped
tail -f now exits immediately if the output is piped
and the reader of the pipe terminates.

tail -f no longer erroneously warns about being ineffective
when following a single tty, as the simple blocking loop used
is effective in this case.


* Noteworthy changes in release 8.27 (2017-03-08) [stable]

Expand Down
18 changes: 14 additions & 4 deletions src/tail.c
Original file line number Diff line number Diff line change
Expand Up @@ -2365,12 +2365,22 @@ main (int argc, char **argv)
if (found_hyphen && follow_mode == Follow_name)
die (EXIT_FAILURE, 0, _("cannot follow %s by name"), quoteaf ("-"));

/* When following forever, warn if any file is '-'.
/* When following forever, and not using simple blocking, warn if
any file is '-' as the stats() used to check for input are ineffective.
This is only a warning, since tail's output (before a failing seek,
and that from any non-stdin files) might still be useful. */
if (forever && found_hyphen && isatty (STDIN_FILENO))
error (0, 0, _("warning: following standard input"
" indefinitely is ineffective"));
if (forever && found_hyphen)
{
struct stat in_stat;
bool blocking_stdin;
blocking_stdin = (pid == 0 && follow_mode == Follow_descriptor
&& n_files == 1 && ! fstat (STDIN_FILENO, &in_stat)
&& ! S_ISREG (in_stat.st_mode));

if (! blocking_stdin && isatty (STDIN_FILENO))
error (0, 0, _("warning: following standard input"
" indefinitely is ineffective"));
}
}

/* Don't read anything if we'll never output anything. */
Expand Down
21 changes: 20 additions & 1 deletion tests/tail-2/follow-stdin.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/sh
# tail -f - would fail with the initial inotify implementation
# Test tail -f -

# Copyright (C) 2009-2017 Free Software Foundation, Inc.

Expand All @@ -19,6 +19,9 @@
. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
print_ver_ tail

#################
# tail -f - would fail with the initial inotify implementation

check_tail_output()
{
local delay="$1"
Expand Down Expand Up @@ -51,6 +54,7 @@ for mode in '' '---disable-inotify'; do
done


#################
# Before coreutils-8.26 this would induce an UMR under UBSAN
returns_ 1 timeout 10 tail -f - <&- 2>errt || fail=1
cat <<\EOF >exp || framework_failure_
Expand All @@ -63,4 +67,19 @@ sed 's/\(tail:.*\):.*/\1/' errt > err || framework_failure_
compare exp err || fail=1


#################
# Before coreutils-8.28 this would erroneously issue a warning
if tty -s </dev/tty && test -t 0; then
for input in '' '-' '/dev/tty'; do
returns_ 124 timeout 0.1 tail -f $input 2>err || fail=1
compare /dev/null err || fail=1
done

tail -f - /dev/null </dev/tty 2> out & pid=$!
# Wait up to 12.7s for output to appear:
tail_re='ineffective' retry_delay_ check_tail_output .1 7 ||
{ cat out; fail=1; }
cleanup_
fi

Exit $fail

0 comments on commit aab875a

Please sign in to comment.