On 11/04/2022 02:44, Bruno Haible wrote:
Pádraig Brady wrote:
FAIL: tests/tail-2/pipe-f
=========================
The following might help here:
diff --git a/src/tail.c b/src/tail.c
index f1b741783..a28fa61da 100644
--- a/src/tail.c
+++ b/src/tail.c
@@ -356,7 +356,7 @@ check_output_alive (void)
event immediately) or if using inotify (which relies on 'poll'
anyway). Otherwise, use 'select' as it's more portable;
'poll' doesn't work for this application on macOS. */
-#if defined _AIX || HAVE_INOTIFY
+#if defined _AIX || defined __sun || HAVE_INOTIFY
struct pollfd pfd;
pfd.fd = STDOUT_FILENO;
pfd.events = POLLERR;
I tried this change, together with an analogous change in line 58
(otherwise it would not compile). It does not fix the test failure;
new test-suite.log is attached.
The attached fixes this issue in my testing.
thanks,
Pádraig
From dc959bf7700f48b8e4ddb1fb9bf529f99b9ab5ac Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C3=A1draig=20Brady?= <p...@draigbrady.com>
Date: Wed, 13 Apr 2022 17:31:47 +0100
Subject: [PATCH] tail: detect closed stdout on Solaris
* src/tail.c (check_output_alive): Use poll() on Solaris.
Also handle POLLHUP, which Solaris returns in this case.
* tests/tail-2/pipe-f.sh: Use `head -n2` rather than `sed 2q`
as Solaris sed does not exit in this case.
* NEWS: Mention the improvement.
Reported by Bruno Haible.
---
NEWS | 2 ++
src/tail.c | 8 ++++----
tests/tail-2/pipe-f.sh | 4 ++--
3 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/NEWS b/NEWS
index 85fd5be12..faac5c543 100644
--- a/NEWS
+++ b/NEWS
@@ -117,6 +117,8 @@ GNU coreutils NEWS -*- outline -*-
sort --debug now diagnoses issues with --field-separator characters
that conflict with characters possibly used in numbers.
+ 'tail -f file | filter' now exits on Solaris when filter exits.
+
root invoked coreutils, that are built and run in single binary mode,
now adjust /proc/$pid/cmdline to be more specific to the utility
being run, rather than using the general "coreutils" binary name.
diff --git a/src/tail.c b/src/tail.c
index f1b741783..a4a590a79 100644
--- a/src/tail.c
+++ b/src/tail.c
@@ -55,7 +55,7 @@
# include <sys/inotify.h>
#endif
-#if defined _AIX || HAVE_INOTIFY
+#if defined _AIX || defined __sun || HAVE_INOTIFY
# include <poll.h>
#endif
@@ -356,12 +356,12 @@ check_output_alive (void)
event immediately) or if using inotify (which relies on 'poll'
anyway). Otherwise, use 'select' as it's more portable;
'poll' doesn't work for this application on macOS. */
-#if defined _AIX || HAVE_INOTIFY
+#if defined _AIX || defined __sun || HAVE_INOTIFY
struct pollfd pfd;
pfd.fd = STDOUT_FILENO;
- pfd.events = POLLERR;
+ pfd.events = pfd.revents = 0;
- if (poll (&pfd, 1, 0) >= 0 && (pfd.revents & POLLERR))
+ if (poll (&pfd, 1, 0) >= 0 && (pfd.revents & (POLLERR | POLLHUP)))
die_pipe ();
#else
struct timeval delay;
diff --git a/tests/tail-2/pipe-f.sh b/tests/tail-2/pipe-f.sh
index 97d5bce69..4ca43a3ea 100755
--- a/tests/tail-2/pipe-f.sh
+++ b/tests/tail-2/pipe-f.sh
@@ -17,7 +17,7 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.
. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
-print_ver_ tail test
+print_ver_ tail test head
trap_sigpipe_or_skip_
# Speedup the non inotify case
@@ -45,7 +45,7 @@ for disposition in '' '-'; do
(trap "$disposition" PIPE;
returns_ 124 timeout 10 \
tail -n2 -f $mode $fastpoll out && touch timed_out) |
- sed 2q > out2
+ head -n2 > out2
test -e timed_out && fail=1
compare exp out2 || fail=1
rm -f timed_out
--
2.26.2