Skip to content

Commit 2ac5e47

Browse files
committed
main/poll: Record wait() error on every backend
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
1 parent 77a9796 commit 2ac5e47

3 files changed

Lines changed: 12 additions & 2 deletions

File tree

main/poll/poll_backend_epoll.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,8 @@ static int epoll_backend_wait(
195195
events[i].revents = epoll_events_from_native(backend_data->events[i].events);
196196
events[i].data = backend_data->events[i].data.ptr;
197197
}
198+
} else if (nfds < 0) {
199+
php_poll_set_current_errno_error(ctx);
198200
}
199201

200202
return nfds;

main/poll/poll_backend_kqueue.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,11 @@ static int kqueue_backend_wait(
320320
int nfds = kevent(
321321
backend_data->kqueue_fd, NULL, 0, backend_data->events, required_capacity, timeout);
322322

323+
if (nfds < 0) {
324+
php_poll_set_current_errno_error(ctx);
325+
return -1;
326+
}
327+
323328
if (nfds > 0) {
324329
if (ctx->raw_events) {
325330
/* Raw events mode - direct 1:1 mapping, no grouping */

main/poll/poll_backend_poll.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,11 @@ static int poll_backend_wait(
215215
int timeout_ms = php_poll_timespec_to_ms(timeout);
216216
int nfds = poll(backend_data->temp_fds, fd_count, timeout_ms);
217217

218-
if (nfds <= 0) {
219-
return nfds; /* Return 0 for timeout, -1 for error */
218+
if (nfds < 0) {
219+
php_poll_set_current_errno_error(ctx);
220+
return -1;
221+
} else if (nfds == 0) {
222+
return 0; /* timeout */
220223
}
221224

222225
/* Process results - iterate through struct pollfd array directly */

0 commit comments

Comments
 (0)