On 21/09/2021 05:34, Jim Meyering wrote:
Uname -v reports this:
Darwin Kernel Version 20.6.0: Mon Aug 30 06:12:21 PDT 2021;
root:xnu-7195.141.6~3/RELEASE_X86_64
Sorry, I don't have time to delve into this, but here's the log from
the sole test failure:
This looks to be an instance I was worried about in:
https://lists.gnu.org/archive/html/bug-coreutils/2021-06/msg00052.html
The attached fixes this on my testing on macOS.
cheers,
Pádraig
>From 8c7b00d85aa01667f747c0e3ef215d0f53ddc6e7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C3=A1draig=20Brady?= <p...@draigbrady.com>
Date: Tue, 21 Sep 2021 14:01:34 +0100
Subject: [PATCH] tail: fix detection of closed stdout on macOS
* bootstrap.conf: We only need poll on Linux and AIX
where poll is not replaced. Also resinstate dependence
on select so we can use it unconditionally.
* src/tail.c (check_output_alive): Reinstate use of select()
by default as poll was seen to be ineffective for this
application on macOS.
Fixes https://bugs.gnu.org/50714
---
bootstrap.conf | 2 +-
src/tail.c | 23 ++++++++++++++++++++++-
2 files changed, 23 insertions(+), 2 deletions(-)
diff --git a/bootstrap.conf b/bootstrap.conf
index bcfc6f0a0..aef9ec7de 100644
--- a/bootstrap.conf
+++ b/bootstrap.conf
@@ -194,7 +194,6 @@ gnulib_modules="
physmem
pipe-posix
pipe2
- poll
posix-shell
posixtm
posixver
@@ -230,6 +229,7 @@ gnulib_modules="
save-cwd
savedir
savewd
+ select
selinux-at
setenv
settime
diff --git a/src/tail.c b/src/tail.c
index eb15b933f..dc5c658f3 100644
--- a/src/tail.c
+++ b/src/tail.c
@@ -28,7 +28,7 @@
#include <stdio.h>
#include <assert.h>
#include <getopt.h>
-#include <poll.h>
+#include <sys/select.h>
#include <sys/types.h>
#include <signal.h>
@@ -55,6 +55,10 @@
# include <sys/inotify.h>
#endif
+#if defined _AIX || HAVE_INOTIFY
+# include <poll.h>
+#endif
+
/* Linux can optimize the handling of local files. */
#if defined __linux__ || defined __ANDROID__
# include "fs.h"
@@ -348,12 +352,29 @@ check_output_alive (void)
if (! monitor_output)
return;
+#ifdef _AIX
+ /* select on AIX was seen to give a readable event immediately.
+ Note poll doesn't work for this application on macOS. */
struct pollfd pfd;
pfd.fd = STDOUT_FILENO;
pfd.events = POLLERR;
if (poll (&pfd, 1, 0) >= 0 && (pfd.revents & POLLERR))
die_pipe ();
+#else
+ struct timeval delay;
+ delay.tv_sec = delay.tv_usec = 0;
+
+ fd_set rfd;
+ FD_ZERO (&rfd);
+ FD_SET (STDOUT_FILENO, &rfd);
+
+ /* readable event on STDOUT is equivalent to POLLERR,
+ and implies an error condition on output like broken pipe. */
+ if (select (STDOUT_FILENO + 1, &rfd, NULL, NULL, &delay) == 1)
+ die_pipe ();
+#endif
+
}
static bool
--
2.26.2