#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
+++ /dev/null
-/*
- * 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;
-}
+++ /dev/null
-/*
- * 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
+++ /dev/null
-/*
- * 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;
-}
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
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
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
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;
}
* 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
#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