support poll(2).
Obtained from: KAME MFC after: 1 week
This commit is contained in:
parent
0b22953b4c
commit
5c706347d5
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=118916
@ -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
|
||||
|
@ -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
|
||||
|
@ -55,6 +55,10 @@
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <syslog.h>
|
||||
#ifdef HAVE_POLL_H
|
||||
#include <poll.h>
|
||||
#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 */
|
||||
|
@ -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
|
||||
|
@ -52,6 +52,9 @@
|
||||
#include <err.h>
|
||||
#include <stdarg.h>
|
||||
#include <ifaddrs.h>
|
||||
#ifdef HAVE_POLL_H
|
||||
#include <poll.h>
|
||||
#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 */
|
||||
|
Loading…
Reference in New Issue
Block a user