Author: hrs
Date: Thu Sep 10 06:40:28 2015
New Revision: 287612
URL: https://svnweb.freebsd.org/changeset/base/287612

Log:
  - Remove #ifdef HAVE_POLL_H.
  - Use nitems().
  
  MFC after:    3 days

Modified:
  head/sbin/rtsol/Makefile
  head/usr.sbin/rtsold/Makefile
  head/usr.sbin/rtsold/if.c
  head/usr.sbin/rtsold/rtsold.c

Modified: head/sbin/rtsol/Makefile
==============================================================================
--- head/sbin/rtsol/Makefile    Thu Sep 10 06:31:24 2015        (r287611)
+++ head/sbin/rtsol/Makefile    Thu Sep 10 06:40:28 2015        (r287612)
@@ -14,15 +14,13 @@
 #
 # $FreeBSD$
 
-SRCDIR=        ${.CURDIR}/../../usr.sbin/rtsold
-
-.PATH: ${SRCDIR}
+.PATH: ${.CURDIR}/../../usr.sbin/rtsold
 
 PROG=  rtsol
 SRCS=  rtsold.c rtsol.c if.c probe.c dump.c rtsock.c
 MAN=
 
 WARNS?=        3
-CFLAGS+= -DHAVE_ARC4RANDOM -DHAVE_POLL_H -DSMALL
+CFLAGS+= -DHAVE_ARC4RANDOM -DSMALL
 
 .include <bsd.prog.mk>

Modified: head/usr.sbin/rtsold/Makefile
==============================================================================
--- head/usr.sbin/rtsold/Makefile       Thu Sep 10 06:31:24 2015        
(r287611)
+++ head/usr.sbin/rtsold/Makefile       Thu Sep 10 06:40:28 2015        
(r287612)
@@ -20,6 +20,6 @@ MLINKS=       rtsold.8 rtsol.8
 SRCS=  rtsold.c rtsol.c if.c probe.c dump.c rtsock.c
 
 WARNS?=        3
-CFLAGS+= -DHAVE_ARC4RANDOM -DHAVE_POLL_H
+CFLAGS+= -DHAVE_ARC4RANDOM
 
 .include <bsd.prog.mk>

Modified: head/usr.sbin/rtsold/if.c
==============================================================================
--- head/usr.sbin/rtsold/if.c   Thu Sep 10 06:31:24 2015        (r287611)
+++ head/usr.sbin/rtsold/if.c   Thu Sep 10 06:40:28 2015        (r287612)
@@ -280,18 +280,18 @@ lladdropt_fill(struct sockaddr_dl *sdl, 
 struct sockaddr_dl *
 if_nametosdl(char *name)
 {
-       int mib[6] = {CTL_NET, AF_ROUTE, 0, 0, NET_RT_IFLIST, 0};
+       int mib[] = {CTL_NET, AF_ROUTE, 0, 0, NET_RT_IFLIST, 0};
        char *buf, *next, *lim;
        size_t len;
        struct if_msghdr *ifm;
        struct sockaddr *sa, *rti_info[RTAX_MAX];
        struct sockaddr_dl *sdl = NULL, *ret_sdl;
 
-       if (sysctl(mib, 6, NULL, &len, NULL, 0) < 0)
+       if (sysctl(mib, nitems(mib), NULL, &len, NULL, 0) < 0)
                return(NULL);
        if ((buf = malloc(len)) == NULL)
                return(NULL);
-       if (sysctl(mib, 6, buf, &len, NULL, 0) < 0) {
+       if (sysctl(mib, nitems(mib), buf, &len, NULL, 0) < 0) {
                free(buf);
                return (NULL);
        }
@@ -341,7 +341,7 @@ getinet6sysctl(int code)
 
        mib[3] = code;
        size = sizeof(value);
-       if (sysctl(mib, sizeof(mib)/sizeof(mib[0]), &value, &size, NULL, 0) < 0)
+       if (sysctl(mib, nitems(mib), &value, &size, NULL, 0) < 0)
                return (-1);
        else
                return (value);
@@ -356,7 +356,7 @@ setinet6sysctl(int code, int newval)
 
        mib[3] = code;
        size = sizeof(value);
-       if (sysctl(mib, sizeof(mib)/sizeof(mib[0]), &value, &size,
+       if (sysctl(mib, nitems(mib), &value, &size,
            &newval, sizeof(newval)) < 0)
                return (-1);
        else

Modified: head/usr.sbin/rtsold/rtsold.c
==============================================================================
--- head/usr.sbin/rtsold/rtsold.c       Thu Sep 10 06:31:24 2015        
(r287611)
+++ head/usr.sbin/rtsold/rtsold.c       Thu Sep 10 06:40:28 2015        
(r287612)
@@ -57,9 +57,7 @@
 #include <err.h>
 #include <stdarg.h>
 #include <ifaddrs.h>
-#ifdef HAVE_POLL_H
 #include <poll.h>
-#endif
 
 #include "rtsold.h"
 
@@ -116,13 +114,7 @@ main(int argc, char **argv)
        int s, ch, once = 0;
        struct timespec *timeout;
        const char *opts;
-#ifdef HAVE_POLL_H
        struct pollfd set[2];
-#else
-       fd_set *fdsetp, *selectfdp;
-       int fdmasks;
-       int maxfd;
-#endif
        int rtsock;
        char *argv0;
 
@@ -254,40 +246,16 @@ main(int argc, char **argv)
                warnmsg(LOG_ERR, __func__, "failed to open a socket");
                exit(1);
        }
-#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);
        }
-#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) {
-               warnmsg(LOG_ERR, __func__, "malloc");
-               exit(1);
-       }
-       if ((selectfdp = malloc(fdmasks)) == NULL) {
-               warnmsg(LOG_ERR, __func__, "malloc");
-               exit(1);
-       }
-#endif
 
        /* configuration per interface */
        if (ifinit()) {
@@ -328,18 +296,8 @@ main(int argc, char **argv)
                        fclose(fp);
                }
        }
-#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
-
 #ifndef SMALL
                if (do_dump) {  /* SIGUSR1 */
                        do_dump = 0;
@@ -364,11 +322,7 @@ main(int argc, char **argv)
                        if (ifi == NULL)
                                break;
                }
-#ifdef HAVE_POLL_H
                e = poll(set, 2, timeout ? (timeout->tv_sec * 1000 + 
timeout->tv_nsec / 1000 / 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",
@@ -378,17 +332,9 @@ main(int argc, char **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 */
_______________________________________________
[email protected] mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "[email protected]"

Reply via email to