From c5adb1df54e34b57d5c1c33ab552c2db542f9790 Mon Sep 17 00:00:00 2001 From: Taylor R Campbell Date: Mon, 3 Sep 2012 19:34:13 +0000 Subject: [PATCH] Use pollts if it is available but ppoll is not. Also change all references to the poll/select variants to use the UX_ names. All four ways -- select, select & pselect, poll, poll & pollts -- tested on a NetBSD 6.99.4 kernel running a NetBSD 5.1 userland by tweaking config.h by hand. --- src/microcode/configure.ac | 2 +- src/microcode/ux.h | 15 ++++++++++++++- src/microcode/uxio.c | 24 ++++++++++++------------ src/microcode/uxsock.c | 2 +- 4 files changed, 28 insertions(+), 15 deletions(-) diff --git a/src/microcode/configure.ac b/src/microcode/configure.ac index 5120a1e41..dddf87eeb 100644 --- a/src/microcode/configure.ac +++ b/src/microcode/configure.ac @@ -533,7 +533,7 @@ AC_CHECK_FUNCS([lockf log1p]) AC_CHECK_FUNCS([madvise memcpy mkdir mktime modf]) AC_CHECK_FUNCS([nice ntp_adjtime ntp_gettime]) AC_CHECK_FUNCS([openpty]) -AC_CHECK_FUNCS([ppoll poll posix_madvise posix_openpt prealloc]) +AC_CHECK_FUNCS([poll pollts ppoll posix_madvise posix_openpt prealloc]) AC_CHECK_FUNCS([rename rmdir]) AC_CHECK_FUNCS([pselect select setitimer setpgrp setpgrp2 shmat sigaction]) AC_CHECK_FUNCS([sighold socket statfs strchr strerror strstr strtol]) diff --git a/src/microcode/ux.h b/src/microcode/ux.h index 5c875454c..7c002ab87 100644 --- a/src/microcode/ux.h +++ b/src/microcode/ux.h @@ -487,7 +487,7 @@ typedef RETSIGTYPE Tsignal_handler_result; # endif extern char * getenv (const char *); #endif - + #define UX_abort abort #define UX_accept accept #define UX_access access @@ -536,6 +536,8 @@ typedef RETSIGTYPE Tsignal_handler_result; #define UX_open open #define UX_pause pause #define UX_pipe pipe +#define UX_poll poll +#define UX_pselect pselect #define UX_read read #define UX_readlink readlink #define UX_realloc realloc @@ -659,6 +661,17 @@ typedef RETSIGTYPE Tsignal_handler_result; # endif #endif +/* ppoll is Linux's newer name for what was called pollts on BSD. */ + +#ifdef HAVE_PPOLL +# define UX_ppoll ppoll +#else +# ifdef HAVE_POLLTS +# define HAVE_PPOLL +# define UX_ppoll pollts +# endif +#endif + #ifdef _POSIX_VERSION # define ERRNO_NONBLOCK EAGAIN # define FCNTL_NONBLOCK O_NONBLOCK diff --git a/src/microcode/uxio.c b/src/microcode/uxio.c index be4a2f826..533fe6eb3 100644 --- a/src/microcode/uxio.c +++ b/src/microcode/uxio.c @@ -557,7 +557,7 @@ safe_poll (struct pollfd *fds, nfds_t nfds, int blockp) #ifdef HAVE_PPOLL if (!blockp) { - n = poll (fds, nfds, 0); + n = (UX_poll (fds, nfds, 0)); } else { @@ -573,7 +573,7 @@ safe_poll (struct pollfd *fds, nfds_t nfds, int blockp) } else { - n = ppoll (fds, nfds, NULL, &old); + n = (UX_ppoll (fds, nfds, NULL, &old)); } UX_sigprocmask (SIG_SETMASK, &old, NULL); } @@ -583,7 +583,7 @@ safe_poll (struct pollfd *fds, nfds_t nfds, int blockp) (n, (((OS_process_any_status_change ()) || (pending_interrupts_p ())) ? ((errno = EINTR), (-1)) - : (poll (fds, nfds, (blockp ? INFTIM : 0))))); + : (UX_poll (fds, nfds, (blockp ? INFTIM : 0))))); #endif return (n); @@ -595,7 +595,7 @@ OS_test_select_registry (select_registry_t registry, int blockp) struct select_registry_s * r = registry; while (1) { - int nfds = safe_poll ((SR_ENTRIES (r)), (SR_N_FDS (r)), blockp); + int nfds = (safe_poll ((SR_ENTRIES (r)), (SR_N_FDS (r)), blockp)); if (nfds >= 0) return (nfds); if (errno != EINTR) @@ -615,7 +615,7 @@ OS_test_select_descriptor (int fd, int blockp, unsigned int mode) ((pfds [0]) . events) = (DECODE_MODE (mode)); while (1) { - int nfds = safe_poll (pfds, 1, blockp); + int nfds = (safe_poll (pfds, 1, blockp)); if (nfds > 0) return (ENCODE_MODE ((pfds [0]) . revents)); if (nfds == 0) @@ -751,7 +751,7 @@ safe_select (int nfds, SELECT_TYPE *readfds, SELECT_TYPE *writefds, int blockp) #ifdef HAVE_PSELECT if (!blockp) { - n = UX_select (nfds, readfds, writefds, NULL, &zero_timeout); + n = (UX_select (nfds, readfds, writefds, NULL, &zero_timeout)); } else { @@ -767,7 +767,7 @@ safe_select (int nfds, SELECT_TYPE *readfds, SELECT_TYPE *writefds, int blockp) } else { - n = pselect (nfds, readfds, writefds, NULL, NULL, &old); + n = (UX_pselect (nfds, readfds, writefds, NULL, NULL, &old)); } UX_sigprocmask (SIG_SETMASK, &old, NULL); } @@ -794,10 +794,10 @@ OS_test_select_registry (select_registry_t registry, int blockp) (* (SR_RWRITERS (r))) = (* (SR_QWRITERS (r))); while (1) { - int nfds = safe_select (FD_SETSIZE, - (SR_RREADERS (r)), - (SR_RWRITERS (r)), - blockp); + int nfds = (safe_select (FD_SETSIZE, + (SR_RREADERS (r)), + (SR_RWRITERS (r)), + blockp)); if (nfds >= 0) return (nfds); if (errno != EINTR) @@ -830,7 +830,7 @@ OS_test_select_descriptor (int fd, int blockp, unsigned int mode) while (1) { - int nfds = safe_select (fd + 1, &readable, &writeable, blockp); + int nfds = (safe_select (fd + 1, &readable, &writeable, blockp)); if (nfds > 0) return (((FD_ISSET (fd, (&readable))) ? SELECT_MODE_READ : 0) diff --git a/src/microcode/uxsock.c b/src/microcode/uxsock.c index bc4ceec09..5858ac8c1 100644 --- a/src/microcode/uxsock.c +++ b/src/microcode/uxsock.c @@ -78,7 +78,7 @@ do_connect (int s, struct sockaddr * address, socklen_t addr_len) (fds . fd) = s; (fds . events) = (POLLIN | POLLOUT); - nfds = (poll ((&fds), 1, 0)); + nfds = (UX_poll ((&fds), 1, 0)); if ((nfds > 0) && (((fds . revents) & (POLLIN | POLLOUT)) != 0)) break; if ((nfds < 0) && (errno != EINTR)) -- 2.25.1