]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Remove compat for polling, dhcpcd now requires pselect as a minimum fallback.
authorRoy Marples <roy@marples.name>
Tue, 12 May 2015 20:03:36 +0000 (20:03 +0000)
committerRoy Marples <roy@marples.name>
Tue, 12 May 2015 20:03:36 +0000 (20:03 +0000)
common.h
compat/pollts.c [deleted file]
compat/pollts.h [deleted file]
compat/pselect.c [deleted file]
configure
dhcpcd.c
eloop.h

index 76215bf6955ebc32a51044e89c3cd61e9160fbc4..12acf2ce8492f933365f5944130085610fad5316 100644 (file)
--- a/common.h
+++ b/common.h
@@ -54,8 +54,8 @@
 #define USEC_PER_SEC           1000000L
 #define USEC_PER_NSEC          1000L
 #define NSEC_PER_SEC           1000000000L
+#define NSEC_PER_MSEC          1000000L
 #define MSEC_PER_SEC           1000L
-#define MSEC_PER_NSEC          1000000L
 
 /* Some systems don't define timespec macros */
 #ifndef timespecclear
 } while (0 /* CONSTCOND */);
 #define ts_to_ms(ms, tv) do {                                               \
        ms = (tv)->tv_sec * MSEC_PER_SEC;                                    \
-       ms += (tv)->tv_nsec / MSEC_PER_NSEC;                                 \
+       ms += (tv)->tv_nsec / NSEC_PER_MSEC;                                 \
 } while (0 /* CONSTCOND */);
 #define ms_to_ts(tv, ms) do {                                               \
        (tv)->tv_sec = ms / MSEC_PER_SEC;                                    \
        (tv)->tv_nsec = (suseconds_t)(ms - ((tv)->tv_sec * MSEC_PER_SEC))    \
-           * MSEC_PER_NSEC;                                                 \
+           * NSEC_PER_MSEC;                                                 \
 } while (0 /* CONSTCOND */);
 
 #ifndef TIMEVAL_TO_TIMESPEC
diff --git a/compat/pollts.c b/compat/pollts.c
deleted file mode 100644 (file)
index 905dad6..0000000
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * dhcpcd - DHCP client daemon
- * Copyright (c) 2006-2013 Roy Marples <roy@marples.name>
- * All rights reserved
-
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <sys/time.h>
-#include <sys/types.h>
-
-#include <limits.h>
-#include <poll.h>
-#include <signal.h>
-#include <unistd.h>
-
-#include "pollts.h"
-
-#warning "This pollts(2) implementation is not entirely race condition safe."
-#warning "Only operating system support for pollts(2) can correct this."
-
-int
-pollts(struct pollfd *__restrict fds, nfds_t nfds,
-    const struct timespec *__restrict ts, const sigset_t *__restrict sigmask)
-{
-       int r, timeout;
-       sigset_t oldset;
-
-       if (ts == NULL)
-               timeout = -1;
-       else if (ts->tv_sec > INT_MAX / 1000 ||
-           (ts->tv_sec == INT_MAX / 1000 &&
-           (ts->tv_nsec + 999999) / 1000000 > INT_MAX % 1000000))
-               timeout = INT_MAX;
-       else
-               timeout = ts->tv_sec * 1000 + (ts->tv_nsec + 999999) / 1000000;
-       if (sigmask && sigprocmask(SIG_SETMASK, sigmask, &oldset) == -1)
-               return -1;
-       r = poll(fds, nfds, timeout);
-       if (sigmask && sigprocmask(SIG_SETMASK, &oldset, NULL) == -1)
-               return -1;
-
-       return r;
-}
diff --git a/compat/pollts.h b/compat/pollts.h
deleted file mode 100644 (file)
index 8fc63d0..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * dhcpcd - DHCP client daemon
- * Copyright (c) 2006-2013 Roy Marples <roy@marples.name>
- * All rights reserved
-
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#ifndef PPOLL_H
-#define PPOLL_H
-
-#include <poll.h>
-#include <signal.h>
-#include <time.h>
-
-int
-pollts(struct pollfd *__restrict, nfds_t, const struct timespec *__restrict,
-    const sigset_t *__restrict);
-
-#endif
diff --git a/compat/pselect.c b/compat/pselect.c
deleted file mode 100644 (file)
index 78911fa..0000000
+++ /dev/null
@@ -1,65 +0,0 @@
-/* 
- * dhcpcd - DHCP client daemon
- * Copyright (c) 2006-2013 Roy Marples <roy@marples.name>
- * All rights reserved
-
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <sys/time.h>
-#include <sys/types.h>
-
-#include <limits.h>
-#include <poll.h>
-#include <signal.h>
-#include <unistd.h>
-
-#include "pollts.h"
-
-int
-pollts(struct pollfd *__restrict fds, nfds_t nfds,
-    const struct timespec *__restrict ts, const sigset_t *__restrict sigmask)
-{
-       fd_set read_fds;
-       nfds_t n;
-       int maxfd, r;
-
-       FD_ZERO(&read_fds);
-       maxfd = 0;
-       for (n = 0; n < nfds; n++) {
-               if (fds[n].events & POLLIN) {
-                       FD_SET(fds[n].fd, &read_fds);
-                       if (fds[n].fd > maxfd)
-                               maxfd = fds[n].fd;
-               }
-       }
-
-       r = pselect(maxfd + 1, &read_fds, NULL, NULL, ts, sigmask);
-       if (r > 0) {
-               for (n = 0; n < nfds; n++) {
-                       fds[n].revents =
-                           FD_ISSET(fds[n].fd, &read_fds) ? POLLIN : 0;
-               }
-       }
-
-       return r;
-}
index b1fec5cc0ff86e7ac795513599299c3be2befed1..48994d3946ebf544ce8da80ee293cb9928d89cfe 100755 (executable)
--- a/configure
+++ b/configure
@@ -424,7 +424,7 @@ if $XCC _test.c -o _test >/dev/null 2>&3; then
 fi
 rm -f _test.c _test
 if ! $_CC; then
-       echo "$CC does not create executables"
+       echo "$CC does not create executables" >&2
        exit 1
 fi
 [ "$CC" != cc ] && echo "CC=   $CC" >>$CONFIG_MK
@@ -852,24 +852,6 @@ EOF
        fi
        rm -f _epoll.c _epoll
 fi
-if [ -z "$POLL" ]; then
-       printf "Testing for ppoll ... "
-       cat <<EOF >_ppoll.c
-#include <poll.h>
-#include <stdlib.h>
-int main(void) {
-       ppoll(NULL, 0, NULL, NULL);
-       return 0;
-}
-EOF
-       if $XCC _ppoll.c -o _ppoll 2>&3; then
-               POLL=ppoll
-               echo "yes"
-       else
-               echo "no"
-       fi
-       rm -f _ppoll.c _ppoll
-fi
 if [ -z "$POLL" ]; then
        printf "Testing for pselect ... "
        cat <<EOF >_pselect.c
@@ -907,8 +889,8 @@ pselect)
        echo "#include          \"compat/pollts.h\"" >>$CONFIG_H
        ;;
 *)
-       echo "COMPAT_SRCS+=     compat/pollts.c" >>$CONFIG_MK
-       echo "#include          \"compat/pollts.h\"" >>$CONFIG_H
+       echo "No suitable polling function is available, not even pselect" >&2
+       exit 1
        ;;
 esac
 
index 28bb828a85db08e2ca7d775d03cafaabdb48eba1..d4b245ce0d3722058f6a5cf4059c096e6a075818 100644 (file)
--- a/dhcpcd.c
+++ b/dhcpcd.c
@@ -584,7 +584,7 @@ dhcpcd_pollup(void *arg)
                struct timespec tv;
 
                tv.tv_sec = 0;
-               tv.tv_nsec = IF_POLL_UP * MSEC_PER_NSEC;
+               tv.tv_nsec = IF_POLL_UP * NSEC_PER_MSEC;
                eloop_timeout_add_tv(ifp->ctx->eloop, &tv, dhcpcd_pollup, ifp);
                return;
        }
@@ -751,7 +751,7 @@ dhcpcd_startinterface(void *arg)
                         * Loop until both IFF_UP and IFF_RUNNING are set */
                        if ((carrier = if_carrier(ifp)) == LINK_UNKNOWN) {
                                tv.tv_sec = 0;
-                               tv.tv_nsec = IF_POLL_UP * MSEC_PER_NSEC;
+                               tv.tv_nsec = IF_POLL_UP * NSEC_PER_MSEC;
                                eloop_timeout_add_tv(ifp->ctx->eloop,
                                    &tv, dhcpcd_startinterface, ifp);
                        } else
diff --git a/eloop.h b/eloop.h
index 74189d55bda90b56e94d78ef0a88473d882ca483..5fda52ba1d14dbb0a43bab225569748535232f37 100644 (file)
--- a/eloop.h
+++ b/eloop.h
@@ -33,7 +33,8 @@
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #else
-/* Attempt to autodetect kqueue or epoll */
+/* Attempt to autodetect kqueue or epoll.
+ * If we can't, the system has to support pselect, which is a POSIX call. */
 #if (defined(__unix__) || defined(unix)) && !defined(USG)
 #include <sys/param.h>
 #endif