Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ping.c
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ int ping_udp(host_t *host, ping_t *ping) {

/* wait for a response on the socket */
wait_more:
return_code = select(FD_SETSIZE, &socket_fds, NULL, NULL, &timeout);
return_code = select(udp_socket + 1, &socket_fds, NULL, NULL, &timeout);

Comment on lines 651 to 654
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

select() modifies both the fd_set and the timeout structure in-place, and POSIX leaves their contents unspecified on error (including EINTR). In this loop, socket_fds is only initialized once before while (1), then reused across retries and the goto wait_more path, which can leave the set empty after the first timeout/error and prevent subsequent retries from ever observing udp_socket readability. Re-initialize socket_fds (and ensure timeout is in the intended state) immediately before each select() call, including when retrying after EINTR.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct that select() modifies the fd_set and timeout. Both are reinitialized before each select call in the existing code (FD_ZERO+FD_SET before each call). The timeout struct is also re-set. No regression.

/* record end time */
end_time = get_time_as_double();
Expand Down
2 changes: 1 addition & 1 deletion poller.c
Original file line number Diff line number Diff line change
Expand Up @@ -2398,7 +2398,7 @@ char *exec_poll(host_t *current_host, char *command, int id, const char *type) {
FD_SET(cmd_fd, &fds);

/* wait x seconds for pipe response */
switch (select(FD_SETSIZE, &fds, NULL, NULL, &timeout)) {
switch (select(cmd_fd + 1, &fds, NULL, NULL, &timeout)) {
case -1:
switch (errno) {
case EBADF:
Expand Down
Loading