From: Roy Marples Date: Fri, 1 Aug 2008 08:41:25 +0000 (+0000) Subject: Tweak README about monotonic, and improve warning message. X-Git-Tag: v4.0.2~97 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8fd2efb43e5d216dadd6386d7e26663b22f2144f;p=thirdparty%2Fdhcpcd.git Tweak README about monotonic, and improve warning message. --- diff --git a/README b/README index d84ab755..ef7e7842 100644 --- a/README +++ b/README @@ -15,12 +15,15 @@ If you're cross compiling you may need to set the below knobs to avoid automatic tests. OS=BSD | Linux -If you're building for a NOMMU system where fork() does not work, you should -add -DTHERE_IS_NO_FORK to your CPPFLAGS. +If you're building for an MMU-less system where fork() does not work, you +should add -DTHERE_IS_NO_FORK to your CPPFLAGS. dhcpcd will try and use a monotonic clock when possible. Some libc implementations do not correctly report that they have a monotonic clock, but they have the headers to make it work. dhcpcd will warn about this. +Without a monotonic clock, we fall victim of the year 2038 time_t bug on +32-bit platforms AND the timers will be sufer from clock skew if the system +clock changes. To force the use of a monotonic clock you can add -DFORCE_MONOTONIC to your CPPFLAGS. diff --git a/client.c b/client.c index f68bafa6..346da0ce 100644 --- a/client.c +++ b/client.c @@ -870,7 +870,7 @@ wait_for_fd(struct if_state *state, int *fd) else if (iface->arp_fd != -1 && FD_ISSET(iface->arp_fd, &fds)) *fd = iface->arp_fd; } else { - /* select and poll are CAN timeout BEFORE the timeout. + /* select and poll CAN timeout BEFORE the timeout. * This is a sad state of affairs, so we need to reduce the * lowest timeout to -1 so it REALLY has timed out. */ ref = get_lowest_timer(state); diff --git a/common.c b/common.c index 9911b345..9bedc6de 100644 --- a/common.c +++ b/common.c @@ -184,13 +184,14 @@ set_nonblock(int fd) * Which is why we use CLOCK_MONOTONIC, but it is not available on all * platforms. */ +#define NO_MONOTONIC "host does not support a montonic clock - timing can skew" int get_monotonic(struct timeval *tp) { + static int posix_clock_set = 0; #if defined(_POSIX_MONOTONIC_CLOCK) && defined(CLOCK_MONOTONIC) struct timespec ts; static clockid_t posix_clock; - static int posix_clock_set = 0; #ifdef FORCE_MONOTONIC if (!posix_clock_set) { @@ -205,7 +206,7 @@ get_monotonic(struct timeval *tp) clock_monotonic = 1; } else { posix_clock = CLOCK_REALTIME; - logger(LOG_WARNING, "host does not support a monotonic clock"); + logger(LOG_WARNING, NO_MONOTONIC); } posix_clock_set = 1; @@ -219,6 +220,11 @@ get_monotonic(struct timeval *tp) tp->tv_usec = ts.tv_nsec / 1000; return 0; #else + + if (!posix_clock_set) { + logger(LOG_WARNING, NO_MONOTONIC); + posix_clock_set = 1; + } return gettimeofday(tp, NULL); #endif }