Fix building with select (not poll) when fd_set is not defined in sys/types.h.

We can use a void * for the fd_set arrays and just add a cast when
using the FD_SET macros.
This commit is contained in:
Todd C. Miller
2022-06-06 19:42:29 -06:00
parent c2a131714a
commit b77cbb2e67
2 changed files with 12 additions and 12 deletions

View File

@@ -102,10 +102,10 @@ struct sudo_event_base {
int pfd_high; /* highest slot used */ int pfd_high; /* highest slot used */
int pfd_free; /* idx of next free entry or pfd_max if full */ int pfd_free; /* idx of next free entry or pfd_max if full */
#else #else
fd_set *readfds_in; /* read I/O descriptor set (in) */ void *readfds_in; /* read I/O descriptor set (in) */
fd_set *writefds_in; /* write I/O descriptor set (in) */ void *writefds_in; /* write I/O descriptor set (in) */
fd_set *readfds_out; /* read I/O descriptor set (out) */ void *readfds_out; /* read I/O descriptor set (out) */
fd_set *writefds_out; /* write I/O descriptor set (out) */ void *writefds_out; /* write I/O descriptor set (out) */
int maxfd; /* max fd we can store in readfds/writefds */ int maxfd; /* max fd we can store in readfds/writefds */
int highfd; /* highest fd to pass as 1st arg to select */ int highfd; /* highest fd to pass as 1st arg to select */
#endif /* HAVE_POLL */ #endif /* HAVE_POLL */

View File

@@ -120,12 +120,12 @@ sudo_ev_add_impl(struct sudo_event_base *base, struct sudo_event *ev)
if (ISSET(ev->events, SUDO_EV_READ)) { if (ISSET(ev->events, SUDO_EV_READ)) {
sudo_debug_printf(SUDO_DEBUG_DEBUG, "%s: added fd %d to readfs", sudo_debug_printf(SUDO_DEBUG_DEBUG, "%s: added fd %d to readfs",
__func__, ev->fd); __func__, ev->fd);
FD_SET(ev->fd, base->readfds_in); FD_SET(ev->fd, (fd_set *)base->readfds_in);
} }
if (ISSET(ev->events, SUDO_EV_WRITE)) { if (ISSET(ev->events, SUDO_EV_WRITE)) {
sudo_debug_printf(SUDO_DEBUG_DEBUG, "%s: added fd %d to writefds", sudo_debug_printf(SUDO_DEBUG_DEBUG, "%s: added fd %d to writefds",
__func__, ev->fd); __func__, ev->fd);
FD_SET(ev->fd, base->writefds_in); FD_SET(ev->fd, (fd_set *)base->writefds_in);
} }
if (ev->fd > base->highfd) if (ev->fd > base->highfd)
base->highfd = ev->fd; base->highfd = ev->fd;
@@ -142,17 +142,17 @@ sudo_ev_del_impl(struct sudo_event_base *base, struct sudo_event *ev)
if (ISSET(ev->events, SUDO_EV_READ)) { if (ISSET(ev->events, SUDO_EV_READ)) {
sudo_debug_printf(SUDO_DEBUG_DEBUG, "%s: removed fd %d from readfds", sudo_debug_printf(SUDO_DEBUG_DEBUG, "%s: removed fd %d from readfds",
__func__, ev->fd); __func__, ev->fd);
FD_CLR(ev->fd, base->readfds_in); FD_CLR(ev->fd, (fd_set *)base->readfds_in);
} }
if (ISSET(ev->events, SUDO_EV_WRITE)) { if (ISSET(ev->events, SUDO_EV_WRITE)) {
sudo_debug_printf(SUDO_DEBUG_DEBUG, "%s: removed fd %d from writefds", sudo_debug_printf(SUDO_DEBUG_DEBUG, "%s: removed fd %d from writefds",
__func__, ev->fd); __func__, ev->fd);
FD_CLR(ev->fd, base->writefds_in); FD_CLR(ev->fd, (fd_set *)base->writefds_in);
} }
if (base->highfd == ev->fd) { if (base->highfd == ev->fd) {
for (;;) { for (;;) {
if (FD_ISSET(base->highfd, base->readfds_in) || if (FD_ISSET(base->highfd, (fd_set *)base->readfds_in) ||
FD_ISSET(base->highfd, base->writefds_in)) FD_ISSET(base->highfd, (fd_set *)base->writefds_in))
break; break;
if (--base->highfd < 0) if (--base->highfd < 0)
break; break;
@@ -230,9 +230,9 @@ sudo_ev_scan_impl(struct sudo_event_base *base, int flags)
TAILQ_FOREACH(ev, &base->events, entries) { TAILQ_FOREACH(ev, &base->events, entries) {
if (ev->fd >= 0) { if (ev->fd >= 0) {
int what = 0; int what = 0;
if (FD_ISSET(ev->fd, base->readfds_out)) if (FD_ISSET(ev->fd, (fd_set *)base->readfds_out))
what |= (ev->events & SUDO_EV_READ); what |= (ev->events & SUDO_EV_READ);
if (FD_ISSET(ev->fd, base->writefds_out)) if (FD_ISSET(ev->fd, (fd_set *)base->writefds_out))
what |= (ev->events & SUDO_EV_WRITE); what |= (ev->events & SUDO_EV_WRITE);
if (what != 0) { if (what != 0) {
/* Make event active. */ /* Make event active. */