From 31525675904b199e80556db53c70d0777975e999 Mon Sep 17 00:00:00 2001 From: ume Date: Thu, 14 Aug 2003 18:43:57 +0000 Subject: support poll(2). Obtained from: KAME MFC after: 1 week --- sbin/rtsol/Makefile | 2 +- usr.sbin/rtadvd/Makefile | 2 +- usr.sbin/rtadvd/rtadvd.c | 37 ++++++++++++++++++++++++++++++++++++- usr.sbin/rtsold/Makefile | 2 +- usr.sbin/rtsold/rtsold.c | 40 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 79 insertions(+), 4 deletions(-) diff --git a/sbin/rtsol/Makefile b/sbin/rtsol/Makefile index 4287d98..337f8c3 100644 --- a/sbin/rtsol/Makefile +++ b/sbin/rtsol/Makefile @@ -18,7 +18,7 @@ SRCDIR= ${.CURDIR}/../../usr.sbin/rtsold PROG= rtsol SRCS= rtsold.c rtsol.c if.c probe.c dump.c rtsock.c -CFLAGS+=-DINET6 -DHAVE_GETIFADDRS +CFLAGS+=-DINET6 -DHAVE_POLL_H WARNS= 0 NOMAN= yes diff --git a/usr.sbin/rtadvd/Makefile b/usr.sbin/rtadvd/Makefile index 99a668d..179ba4e 100644 --- a/usr.sbin/rtadvd/Makefile +++ b/usr.sbin/rtadvd/Makefile @@ -18,7 +18,7 @@ PROG= rtadvd MAN= rtadvd.conf.5 rtadvd.8 SRCS= rtadvd.c rrenum.c advcap.c if.c config.c timer.c dump.c -CFLAGS+= -DINET6 +CFLAGS+= -DINET6 -DHAVE_POLL_H DPADD= ${LIBCOMPAT} LDADD= -lcompat diff --git a/usr.sbin/rtadvd/rtadvd.c b/usr.sbin/rtadvd/rtadvd.c index cecda2b..b4746c6 100644 --- a/usr.sbin/rtadvd/rtadvd.c +++ b/usr.sbin/rtadvd/rtadvd.c @@ -55,6 +55,10 @@ #include #include #include +#ifdef HAVE_POLL_H +#include +#endif + #include "rtadvd.h" #include "rrenum.h" #include "advcap.h" @@ -145,9 +149,13 @@ main(argc, argv) int argc; char *argv[]; { +#ifdef HAVE_POLL_H + struct pollfd set[2]; +#else fd_set *fdsetp, *selectfdp; int fdmasks; int maxfd = 0; +#endif struct timeval *timeout; int i, ch; int fflag = 0; @@ -236,6 +244,16 @@ main(argc, argv) fclose(pidfp); } +#ifdef HAVE_POLL_H + set[0].fd = sock; + set[0].events = POLLIN; + if (sflag == 0) { + rtsock_open(); + set[1].fd = rtsock; + set[1].events = POLLIN; + } else + set[1].fd = -1; +#else maxfd = sock; if (sflag == 0) { rtsock_open(); @@ -257,12 +275,15 @@ main(argc, argv) FD_SET(sock, fdsetp); if (rtsock >= 0) FD_SET(rtsock, fdsetp); +#endif signal(SIGTERM, set_die); signal(SIGUSR1, rtadvd_set_dump_file); while (1) { +#ifndef HAVE_POLL_H memcpy(selectfdp, fdsetp, fdmasks); /* reinitialize */ +#endif if (do_dump) { /* SIGUSR1 */ do_dump = 0; @@ -289,8 +310,14 @@ main(argc, argv) __func__); } +#ifdef HAVE_POLL_H + if ((i = poll(set, 2, timeout ? (timeout->tv_sec * 1000 + + timeout->tv_usec / 1000) : INFTIM)) < 0) +#else if ((i = select(maxfd + 1, selectfdp, NULL, NULL, - timeout)) < 0) { + timeout)) < 0) +#endif + { /* EINTR would occur upon SIGUSR1 for status dump */ if (errno != EINTR) syslog(LOG_ERR, "<%s> select: %s", @@ -299,9 +326,17 @@ main(argc, argv) } if (i == 0) /* timeout */ continue; +#ifdef HAVE_POLL_H + if (rtsock != -1 && set[1].revents & POLLIN) +#else if (rtsock != -1 && FD_ISSET(rtsock, selectfdp)) +#endif rtmsg_input(); +#ifdef HAVE_POLL_H + if (set[0].revents & POLLIN) +#else if (FD_ISSET(sock, selectfdp)) +#endif rtadvd_input(); } exit(0); /* NOTREACHED */ diff --git a/usr.sbin/rtsold/Makefile b/usr.sbin/rtsold/Makefile index 510e2dd..6ae47e9 100644 --- a/usr.sbin/rtsold/Makefile +++ b/usr.sbin/rtsold/Makefile @@ -19,7 +19,7 @@ MAN= rtsold.8 MLINKS= rtsold.8 rtsol.8 SRCS= rtsold.c rtsol.c if.c probe.c dump.c rtsock.c -CFLAGS+= -DINET6 -DHAVE_ARC4RANDOM +CFLAGS+= -DINET6 -DHAVE_ARC4RANDOM -DHAVE_POLL_H DPADD= ${LIBKVM} LDADD= -lkvm diff --git a/usr.sbin/rtsold/rtsold.c b/usr.sbin/rtsold/rtsold.c index d6891e7..82cae73 100644 --- a/usr.sbin/rtsold/rtsold.c +++ b/usr.sbin/rtsold/rtsold.c @@ -52,6 +52,9 @@ #include #include #include +#ifdef HAVE_POLL_H +#include +#endif #include "rtsold.h" @@ -121,9 +124,13 @@ main(argc, argv) int s, ch, once = 0; struct timeval *timeout; char *argv0, *opts; +#ifdef HAVE_POLL_H + struct pollfd set[2]; +#else fd_set *fdsetp, *selectfdp; int fdmasks; int maxfd; +#endif int rtsock; /* @@ -242,15 +249,31 @@ main(argc, argv) exit(1); /*NOTREACHED*/ } +#ifdef HAVE_POLL_H + set[0].fd = s; + set[0].events = POLLIN; +#else maxfd = s; +#endif + +#ifdef HAVE_POLL_H + set[1].fd = -1; +#endif + if ((rtsock = rtsock_open()) < 0) { warnmsg(LOG_ERR, __func__, "failed to open a socket"); exit(1); /*NOTREACHED*/ } +#ifdef HAVE_POLL_H + set[1].fd = rtsock; + set[1].events = POLLIN; +#else if (rtsock > maxfd) maxfd = rtsock; +#endif +#ifndef HAVE_POLL_H fdmasks = howmany(maxfd + 1, NFDBITS) * sizeof(fd_mask); if ((fdsetp = malloc(fdmasks)) == NULL) { err(1, "malloc"); @@ -260,6 +283,7 @@ main(argc, argv) err(1, "malloc"); /*NOTREACHED*/ } +#endif /* configuration per interface */ if (ifinit()) { @@ -301,13 +325,17 @@ main(argc, argv) } } +#ifndef HAVE_POLL_H memset(fdsetp, 0, fdmasks); FD_SET(s, fdsetp); FD_SET(rtsock, fdsetp); +#endif while (1) { /* main loop */ int e; +#ifndef HAVE_POLL_H memcpy(selectfdp, fdsetp, fdmasks); +#endif if (do_dump) { /* SIGUSR1 */ do_dump = 0; @@ -331,7 +359,11 @@ main(argc, argv) if (ifi == NULL) break; } +#ifdef HAVE_POLL_H + e = poll(set, 2, timeout ? (timeout->tv_sec * 1000 + timeout->tv_usec / 1000) : INFTIM); +#else e = select(maxfd + 1, selectfdp, NULL, NULL, timeout); +#endif if (e < 1) { if (e < 0 && errno != EINTR) { warnmsg(LOG_ERR, __func__, "select: %s", @@ -341,9 +373,17 @@ main(argc, argv) } /* packet reception */ +#ifdef HAVE_POLL_H + if (set[1].revents & POLLIN) +#else if (FD_ISSET(rtsock, selectfdp)) +#endif rtsock_input(rtsock); +#ifdef HAVE_POLL_H + if (set[0].revents & POLLIN) +#else if (FD_ISSET(s, selectfdp)) +#endif rtsol_input(s); } /* NOTREACHED */ -- cgit v1.1