From: Roy Marples Date: Fri, 1 Aug 2008 13:15:11 +0000 (+0000) Subject: Brute force detection of monotonic clock as sysconf is unreliable. Instead rely on... X-Git-Tag: v4.0.2~95 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b5329d0e46028d623454756a1da81013474aab65;p=thirdparty%2Fdhcpcd.git Brute force detection of monotonic clock as sysconf is unreliable. Instead rely on clock_gettime failing gracefully with an invalid clockid (which it should do). --- diff --git a/README b/README index ef7e7842..b3550c13 100644 --- a/README +++ b/README @@ -18,15 +18,6 @@ OS=BSD | Linux 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. - You can change the default dir with these knobs. For example, to satisfy FHS compliance you would do this:- LIBEXECDIR=/lib/dhcpcd diff --git a/common.c b/common.c index 9bedc6de..55e4e5ff 100644 --- a/common.c +++ b/common.c @@ -193,25 +193,16 @@ get_monotonic(struct timeval *tp) struct timespec ts; static clockid_t posix_clock; -#ifdef FORCE_MONOTONIC if (!posix_clock_set) { - posix_clock = CLOCK_MONOTONIC; - posix_clock_set = 1; - clock_monotonic = 1; - } -#else - if (!posix_clock_set) { - if (sysconf(_SC_MONOTONIC_CLOCK) >= 0) { + if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0) { posix_clock = CLOCK_MONOTONIC; clock_monotonic = 1; } else { posix_clock = CLOCK_REALTIME; logger(LOG_WARNING, NO_MONOTONIC); } - posix_clock_set = 1; } -#endif if (clock_gettime(posix_clock, &ts) == -1) return -1; @@ -220,7 +211,6 @@ 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;