On Mon, 04 Jul 2016 12:43:12 +0200, Jeremie Courreges-Anglas wrote:
> This was initially prompted by a diff to replace calloc with
> reallocarray. As noted by guenther, there is a problem with the
> comparisons between width, rpcsock and pingsock; this, plus the fd_set
> allocation inconvenience would be easily fixed by moving from select to
> poll.
There were two problems with this diff:
1) wrong size given to memcpy()
2) svc_getreq_poll() takes the return value of poll(), not svc_max_pollfd
This should fix people's YP setup.
- todd
Index: usr.sbin/ypbind/ypbind.c
===================================================================
RCS file: /cvs/src/usr.sbin/ypbind/ypbind.c,v
retrieving revision 1.67
diff -u -p -u -r1.67 ypbind.c
--- usr.sbin/ypbind/ypbind.c 5 Jul 2016 16:41:40 -0000 1.67
+++ usr.sbin/ypbind/ypbind.c 8 Jul 2016 19:23:30 -0000
@@ -338,7 +338,7 @@ main(int argc, char *argv[])
char path[PATH_MAX];
struct sockaddr_in sin;
struct pollfd *pfd = NULL;
- int width = 0, lockfd, lsock;
+ int width = 0, nready, lockfd, lsock;
socklen_t len;
int evil = 0, one = 1;
DIR *dirp;
@@ -540,9 +540,10 @@ main(int argc, char *argv[])
pfd[0].events = POLLIN;
pfd[1].fd = pingsock;
pfd[1].events = POLLIN;
- memcpy(pfd + 2, svc_pollfd, svc_max_pollfd);
+ memcpy(pfd + 2, svc_pollfd, sizeof(*pfd) * svc_max_pollfd);
- switch (poll(pfd, width, 1000)) {
+ nready = poll(pfd, width, 1000);
+ switch (nready) {
case 0:
checkwork();
break;
@@ -552,11 +553,15 @@ main(int argc, char *argv[])
break;
default:
/* No need to check for POLLHUP on UDP sockets. */
- if (pfd[0].revents & POLLIN)
+ if (pfd[0].revents & POLLIN) {
handle_replies();
- if (pfd[1].revents & POLLIN)
+ nready--;
+ }
+ if (pfd[1].revents & POLLIN) {
handle_ping();
- svc_getreq_poll(pfd + 2, svc_max_pollfd);
+ nready--;
+ }
+ svc_getreq_poll(pfd + 2, nready);
if (check)
checkwork();
break;