summaryrefslogtreecommitdiff
path: root/src/tail.c
diff options
context:
space:
mode:
authorJim Meyering <meyering@redhat.com>2009-09-06 09:39:31 +0200
committerJim Meyering <meyering@redhat.com>2009-09-06 09:40:43 +0200
commitd54376db68adf655b5f09855442b2983fc2f4f3e (patch)
tree957e98a9660c3dee1af27a3300aa4d451732731b /src/tail.c
parentaf054f80b24d1ed3ac0cb9c4593eac5f0a3c5788 (diff)
downloadcoreutils-d54376db68adf655b5f09855442b2983fc2f4f3e.tar.xz
tail: flush initial output before possibly blocking
* src/tail.c (main): Flush any output from tail_file, before calling tail_forever_inotify, which can block. * tests/tail-2/flush-initial: New file. Test for the bug. * tests/Makefile.am (TESTS): Add tail-2/flush-initial. * 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".
Diffstat (limited to 'src/tail.c')
-rw-r--r--src/tail.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/tail.c b/src/tail.c
index fee3f1f2d..e3b9529f8 100644
--- a/src/tail.c
+++ b/src/tail.c
@@ -1399,7 +1399,6 @@ tail_forever_inotify (int wd, struct File_spec *f, size_t n_files,
if (fflush (stdout) != 0)
error (EXIT_FAILURE, errno, _("write error"));
}
-
}
#endif
@@ -1990,6 +1989,12 @@ main (int argc, char **argv)
error (0, errno, _("inotify cannot be used, reverting to polling"));
else
{
+ /* Flush any output from tail_file, now, since
+ tail_forever_inotify flushes only after writing,
+ not before reading. */
+ if (fflush (stdout) != 0)
+ error (EXIT_FAILURE, errno, _("write error"));
+
tail_forever_inotify (wd, F, n_files, sleep_interval);
/* The only way the above returns is upon failure. */