[php-src] master: main/poll: Record wait() error on every backend (#22326)

Ilia Alshanetsky via GitHub <[email protected]>
Newsgroups gmane.comp.php.cvs.general
Message-ID <[email protected]>
Author: Ilia Alshanetsky (iliaal)
Committer: GitHub (web-flow)
Pusher: bukka
Date: 2026-07-05T09:17:38+02:00

Commit: https://github.com/php/php-src/commit/2ddbc0a67229cd8f870a2e3777fe769abdc959b5
Raw diff: https://github.com/php/php-src/commit/2ddbc0a67229cd8f870a2e3777fe769abdc959b5.diff

main/poll: Record wait() error on every backend (#22326)

php_poll_wait() reported a stale error code when a backend's wait syscall
failed without recording one: epoll, poll and kqueue returned -1 without
setting it. Record it from errno in those backends so php_poll_get_error()
reflects the actual failure. eventport and wsapoll already did, the
latter from WSAGetLastError().

Closes GH-22326

Changed paths:
  M  main/poll/poll_backend_epoll.c
  M  main/poll/poll_backend_kqueue.c
  M  main/poll/poll_backend_poll.c


Diff:

diff --git a/main/poll/poll_backend_epoll.c b/main/poll/poll_backend_epoll.c
index 685339da77d2..394b0dc52446 100644
--- a/main/poll/poll_backend_epoll.c
+++ b/main/poll/poll_backend_epoll.c
@@ -195,6 +195,8 @@ static int epoll_backend_wait(
 			events[i].revents = epoll_events_from_native(backend_data->events[i].events);
 			events[i].data = backend_data->events[i].data.ptr;
 		}
+	} else if (nfds < 0) {
+		php_poll_set_current_errno_error(ctx);
 	}
 
 	return nfds;
diff --git a/main/poll/poll_backend_kqueue.c b/main/poll/poll_backend_kqueue.c
index 59b5efa9cacb..00ba7abc9ee6 100644
--- a/main/poll/poll_backend_kqueue.c
+++ b/main/poll/poll_backend_kqueue.c
@@ -320,6 +320,11 @@ static int kqueue_backend_wait(
 	int nfds = kevent(
 			backend_data->kqueue_fd, NULL, 0, backend_data->events, required_capacity, timeout);
 
+	if (nfds < 0) {
+		php_poll_set_current_errno_error(ctx);
+		return -1;
+	}
+
 	if (nfds > 0) {
 		if (ctx->raw_events) {
 			/* Raw events mode - direct 1:1 mapping, no grouping */
diff --git a/main/poll/poll_backend_poll.c b/main/poll/poll_backend_poll.c
index cca81b6fc4fb..05a51a04d31d 100644
--- a/main/poll/poll_backend_poll.c
+++ b/main/poll/poll_backend_poll.c
@@ -215,8 +215,11 @@ static int poll_backend_wait(
 	int timeout_ms = php_poll_timespec_to_ms(timeout);
 	int nfds = poll(backend_data->temp_fds, fd_count, timeout_ms);
 
-	if (nfds <= 0) {
-		return nfds; /* Return 0 for timeout, -1 for error */
+	if (nfds < 0) {
+		php_poll_set_current_errno_error(ctx);
+		return -1;
+	} else if (nfds == 0) {
+		return 0; /* timeout */
 	}
 
 	/* Process results - iterate through struct pollfd array directly */
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.