From ba16bdd89064a58d828d557827a473fc02b0d5ad Mon Sep 17 00:00:00 2001 From: =?utf8?q?P=C3=A1draig=20Brady?= Date: Wed, 7 Jun 2017 00:17:57 -0700 Subject: [PATCH] tail: with --pid, ensure all inotify events are processed * NEWS: Mention the bug fix. * src/tail.c (tail_forever_inotify): With --pid, avoid waiting for new events if there are still events to process. * tests/tail-2/inotify-dir-recreate.sh: Adjust to trigger. --- NEWS | 5 +++++ src/tail.c | 2 +- tests/tail-2/inotify-dir-recreate.sh | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/NEWS b/NEWS index c811dbcb5..508c08f6b 100644 --- a/NEWS +++ b/NEWS @@ -31,6 +31,11 @@ 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. + 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] + uptime no longer outputs the AM/PM component of the current time, as that's inconsistent with the 24 hour time format used. [bug introduced in coreutils-7.0] diff --git a/src/tail.c b/src/tail.c index 6328fe0ef..3582321bc 100644 --- a/src/tail.c +++ b/src/tail.c @@ -1577,7 +1577,7 @@ tail_forever_inotify (int wd, struct File_spec *f, size_t n_files, /* When watching a PID, ensure that a read from WD will not block indefinitely. */ - if (pid) + if (pid && (len <= evbuf_off)) { if (writer_is_dead) exit (EXIT_SUCCESS); diff --git a/tests/tail-2/inotify-dir-recreate.sh b/tests/tail-2/inotify-dir-recreate.sh index 02ddf96a4..5c74c1dfa 100755 --- a/tests/tail-2/inotify-dir-recreate.sh +++ b/tests/tail-2/inotify-dir-recreate.sh @@ -54,7 +54,7 @@ grep_timeout_ () mkdir dir && echo 'inotify' > dir/file || framework_failure_ #tail must print content of the file to stdout, verify -timeout 60 tail -F dir/file >out 2>&1 & pid=$! +timeout 60 tail --pid=$$ -F dir/file >out 2>&1 & pid=$! grep_timeout_ 'inotify' 'out' || { cleanup_fail_ 'file to be tailed does not exist'; } -- 2.11.4.GIT