On 01/12/2026 11:48, Bruno Haible wrote:
Hi,
Collin Funk wrote:
BTW, Bruno, this test still fails on OpenBSD after the fix. I suspect it
may be a poll bug, but I need to look into it more.
Indeed. Today's CI reports this failure on OpenBSD 7.9:
FAIL: tests/tee/tee
OpenBSD is using select() within our iopoll() module.
I moved it to the more controllable poll() interface,
which showed up an generalization issue with the previous patch.
Hopefully the attached should address all this.
I rewrote the comments on iopoll_internal(), because they confused me
(even though I previously wrote the function and the comments).
cheers,
Padraig
From 69737cdbde1403c29e9fd7d5690dcd3bc4b04e7d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C3=A1draig=20Brady?= <[email protected]>
Date: Tue, 1 Dec 2026 17:09:19 +0000
Subject: [PATCH] tee: fix detection of closed full pipes on OpenBSD
* src/iopoll.c (iopoll_internal): Use poll() on BSD.
Also generalize the fix in commit v9.12-325-g8efc320e0,
which is required to get the required events on OpenBSD.
---
src/iopoll.c | 47 +++++++++++++++++++++++++++++------------------
1 file changed, 29 insertions(+), 18 deletions(-)
diff --git a/src/iopoll.c b/src/iopoll.c
index 139b29cf2..733178f79 100644
--- a/src/iopoll.c
+++ b/src/iopoll.c
@@ -18,13 +18,16 @@
#include <config.h>
-/* poll(2) is needed on AIX (where 'select' gives a readable
- event immediately) and Solaris (where 'select' never gave
- a readable event). Also use poll(2) on systems we know work
- and/or are already using poll (linux). On macOS we know poll()
- doesn't work on 10.5, while it does work on >= 11 at least. */
+/* poll(2) is needed on:
+ AIX, where 'select' gives a readable event immediately.
+ Solaris, where 'select' never gave a readable event.
+ OpenBSD, where 'select' never gave a writeable event for closed full pipes.
+ Also use poll(2) on systems we know work and/or are already using poll:
+ Linux already uses poll.
+ macOS >= 11 (10.5 at least does not work).
+*/
#if defined _AIX || defined __sun \
- || defined __linux__ || defined __ANDROID__ \
+ || defined __linux__ || defined __ANDROID__ || defined __OpenBSD__ \
|| __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 110000
# define IOPOLL_USES_POLL 1
/* Check we've not enabled gnulib's poll module
@@ -48,24 +51,28 @@
/* BROKEN_OUTPUT selects the mode of operation of this function.
- If BROKEN_OUTPUT, wait for FDIN to become ready for reading
- or FDOUT to become a broken pipe.
- If !BROKEN_OUTPUT, wait for FDIN or FDOUT to become ready for writing.
- If either of those are -1, then they're not checked. Set BLOCK to true
- to wait for an event, otherwise return the status immediately.
- Return 0 if not BLOCKing and there is no event on the requested descriptors.
- Return 0 if FDIN can be read() without blocking, or IOPOLL_BROKEN_OUTPUT if
- FDOUT becomes a broken pipe. If !BROKEN_OUTPUT return 0 if FDOUT writable,
- or has an error that would cause a subsequent write to fail without blocking.
- Otherwise return IOPOLL_ERROR if there is a poll() or select() error. */
+
+ If BROKEN_OUTPUT is true, watch for input on FDIN and a broken pipe on
+ FDOUT. Return 0 if FDIN is ready to read (including EOF), or
+ IOPOLL_BROKEN_OUTPUT if FDOUT is broken. Input takes precedence if
+ both events occur.
+
+ If BROKEN_OUTPUT is false, FDIN must be -1. Wait to retry a write
+ on FDOUT. Return 0 when the write can proceed or report an error
+ such as EPIPE.
+
+ In either mode, ignore a descriptor of -1. If BLOCK is false, check
+ immediately and return 0 if there is no event. Return IOPOLL_ERROR
+ if the poll or select call fails with an error other than EINTR. */
static int
iopoll_internal (int fdin, int fdout, bool block, bool broken_output)
{
affirm (fdin != -1 || fdout != -1);
+ affirm (broken_output || fdin == -1);
#if IOPOLL_USES_POLL
- struct pollfd pfds[2] = { /* POLLRDBAND needed for illumos, macOS. */
+ struct pollfd pfds[2] = { /* POLLRDBAND needed for illumos,macOS,OpenBSD. */
{ .fd = fdin, .events = POLLIN | POLLRDBAND, .revents = 0 },
{ .fd = fdout, .events = POLLRDBAND, .revents = 0 },
};
@@ -74,7 +81,7 @@ iopoll_internal (int fdin, int fdout, bool block, bool broken_output)
if (! broken_output)
{
- pfds[0].events = pfds[1].events = POLLOUT;
+ pfds[1].events |= POLLOUT;
check_out_events |= POLLOUT;
}
@@ -91,6 +98,10 @@ iopoll_internal (int fdin, int fdout, bool block, bool broken_output)
return 0; /* should now be able to read() without blocking */
if (pfds[1].revents & check_out_events)
return broken_output ? IOPOLL_BROKEN_OUTPUT : 0;
+ /* A socket with pending urgent data can keep reporting POLLRDBAND
+ alone. Ignore it on subsequent polls while waiting to write. */
+ if (! broken_output)
+ pfds[1].events &= ~POLLRDBAND;
}
#else /* fall back to select()-based implementation */
--
2.56.0