summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2014-10-31 20:11:53 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2014-10-31 20:11:53 +0000
commitae726bf864b846bd7ad19cc7cfb86bd69c2bd197 (patch)
tree7780f6581fe13af5bde3c96384577b8c3a4c8ebe /usr.sbin
parentf69a987d49dd2793c41cf196572071ac810d1e30 (diff)
convert select() to poll(). Bit more complicated here. Some interesting
discussion with millert about POLLHUP, which is not needed here because this is a bpf description, but indicates we need to consider that elsewhere. ok millert
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/rarpd/rarpd.c45
1 files changed, 22 insertions, 23 deletions
diff --git a/usr.sbin/rarpd/rarpd.c b/usr.sbin/rarpd/rarpd.c
index 6845596f82d..07d86f3628d 100644
--- a/usr.sbin/rarpd/rarpd.c
+++ b/usr.sbin/rarpd/rarpd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rarpd.c,v 1.55 2014/10/29 06:16:34 deraadt Exp $ */
+/* $OpenBSD: rarpd.c,v 1.56 2014/10/31 20:11:52 deraadt Exp $ */
/* $NetBSD: rarpd.c,v 1.25 1998/04/23 02:48:33 mrg Exp $ */
/*
@@ -48,6 +48,7 @@
#include <arpa/inet.h>
#include <dirent.h>
#include <util.h>
+#include <poll.h>
#include <ifaddrs.h>
#include <paths.h>
@@ -384,9 +385,9 @@ rarp_check(u_char *p, int len)
void
rarp_loop(void)
{
- int cc, fd, fdsn, maxfd = 0;
+ int cc, fd, numfd = 0, i;
u_int bufsize;
- fd_set *fdsp, *lfdsp;
+ struct pollfd *pfd;
u_char *buf, *bp, *ep;
struct if_info *ii;
@@ -404,36 +405,33 @@ rarp_loop(void)
/* NOTREACHED */
}
/*
- * Find the highest numbered file descriptor for select().
* Initialize the set of descriptors to listen to.
*/
for (ii = iflist; ii; ii = ii->ii_next)
- if (ii->ii_fd > maxfd)
- maxfd = ii->ii_fd;
-
- fdsn = howmany(maxfd+1, NFDBITS) * sizeof(fd_mask);
- if ((fdsp = (fd_set *)malloc(fdsn)) == NULL)
- error(FATAL, "malloc");
- if ((lfdsp = (fd_set *)malloc(fdsn)) == NULL)
- error(FATAL, "malloc");
-
- memset(fdsp, 0, fdsn);
- for (ii = iflist; ii; ii = ii->ii_next)
- FD_SET(ii->ii_fd, fdsp);
+ numfd++;
+ pfd = reallocarray(NULL, numfd, sizeof(*pfd));
+ if (pfd == NULL) {
+ error(FATAL, "malloc: %s", strerror(errno));
+ /* NOTREACHED */
+ }
+ for (i = 0, ii = iflist; ii; ii = ii->ii_next, i++) {
+ pfd[i].fd = ii->ii_fd;
+ pfd[i].events = POLLIN;
+ }
while (1) {
- memcpy(lfdsp, fdsp, fdsn);
- if (select(maxfd + 1, lfdsp, (fd_set *) 0,
- (fd_set *) 0, (struct timeval *) 0) < 0) {
+ if (poll(pfd, numfd, -1) == -1) {
+ if (errno == EINTR)
+ continue;
error(FATAL, "select: %s", strerror(errno));
/* NOTREACHED */
}
- for (ii = iflist; ii; ii = ii->ii_next) {
- fd = ii->ii_fd;
- if (!FD_ISSET(fd, lfdsp))
+ for (i = 0, ii = iflist; ii; ii = ii->ii_next, i++) {
+ if (pfd[i].revents == 0)
continue;
+ fd = ii->ii_fd;
again:
- cc = read(fd, (char *) buf, bufsize);
+ cc = read(fd, (char *)buf, bufsize);
/* Don't choke when we get ptraced */
if (cc < 0 && errno == EINTR)
goto again;
@@ -456,6 +454,7 @@ rarp_loop(void)
}
}
}
+ free(pfd);
}
#ifndef TFTP_DIR