From: Roy Marples Date: Tue, 12 May 2015 20:03:36 +0000 (+0000) Subject: Remove compat for polling, dhcpcd now requires pselect as a minimum fallback. X-Git-Tag: v6.9.0~33 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9437df595bec332daa160f3be7d217794ab75406;p=thirdparty%2Fdhcpcd.git Remove compat for polling, dhcpcd now requires pselect as a minimum fallback. --- diff --git a/common.h b/common.h index 76215bf6..12acf2ce 100644 --- 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 @@ -95,12 +95,12 @@ } 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 index 905dad6e..00000000 --- a/compat/pollts.c +++ /dev/null @@ -1,63 +0,0 @@ -/* - * dhcpcd - DHCP client daemon - * Copyright (c) 2006-2013 Roy Marples - * 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 -#include - -#include -#include -#include -#include - -#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 index 8fc63d0f..00000000 --- a/compat/pollts.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * dhcpcd - DHCP client daemon - * Copyright (c) 2006-2013 Roy Marples - * 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 -#include -#include - -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 index 78911fa0..00000000 --- a/compat/pselect.c +++ /dev/null @@ -1,65 +0,0 @@ -/* - * dhcpcd - DHCP client daemon - * Copyright (c) 2006-2013 Roy Marples - * 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 -#include - -#include -#include -#include -#include - -#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; -} diff --git a/configure b/configure index b1fec5cc..48994d39 100755 --- 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 <_ppoll.c -#include -#include -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 <_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 diff --git a/dhcpcd.c b/dhcpcd.c index 28bb828a..d4b245ce 100644 --- 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 74189d55..5fda52ba 100644 --- 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 #endif