From: Roy Marples Date: Mon, 22 Oct 2007 14:32:31 +0000 (+0000) Subject: Use sysconf to detect if we have a working monotonic clock. X-Git-Tag: v3.2.3~174 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=33eb264faaa1ca27d1d4ecec8b6c1d98bcb1ece2;p=thirdparty%2Fdhcpcd.git Use sysconf to detect if we have a working monotonic clock. --- diff --git a/ChangeLog b/ChangeLog index d275d479..6d2d69d4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,4 @@ +Use sysconf to detect if we have a working monotonic clock. Only request NTP, NIS, etc if we have compiled that feature in. dhcpcd --version now shows what compile time options were used. diff --git a/Makefile b/Makefile index bb1f00fc..611e2f81 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ # such as the need to link to libresolv and/or librt so please forgive the # embedded code :) -VERSION = 3.1.7 +VERSION = 3.1.8_pre1 CFLAGS += -O2 -pipe INSTALL ?= install @@ -32,15 +32,13 @@ _LIBRESOLV != $(_LIBRESOLV_SH) LIBRESOLV = $(_LIBRESOLV)$(shell $(_LIBRESOLV_SH)) # Work out if we need -lrt or not -_LIBRT_SH = printf '\#include \nint main (void) { struct timespec ts; return (clock_gettime (CLOCK_MONOTONIC, &ts)); }\n' > .clock_gettime.c; \ +_LIBRT_SH = printf '\#include \n\#include \n\nint main (void) { struct timespec ts;\n\#if defined(_POSIX_MONOTONIC_CLOCK) && defined(CLOCK_MONOTONIC)\nreturn (clock_gettime (CLOCK_MONOTONIC, &ts));\n\#else\nreturn -1;\n\#endif\n}\n' > .clock_gettime.c; \ if $(CC) .clock_gettime.c -o .clock_gettime >/dev/null 2>&1; then \ echo ""; \ elif $(CC) .clock_gettime.c -lrt -o .clock_gettime >/dev/null 2>&1 ; then \ echo "-lrt"; \ else \ - echo "Cannot work out how to get clock_gettime to link" >&2; \ - rm -f .clock_gettime.c .clock_gettime; \ - exit 1; \ + echo ""; \ fi; \ rm -f .clock_gettime.c .clock_gettime _LIBRT != $(_LIBRT_SH) diff --git a/common.c b/common.c index 1fb50187..45bd8969 100644 --- a/common.c +++ b/common.c @@ -105,10 +105,20 @@ void close_fds (void) */ int get_time (struct timeval *tp) { -#ifdef CLOCK_MONOTONIC +#if defined(_POSIX_MONOTONIC_CLOCK) && defined(CLOCK_MONOTONIC) struct timespec ts; + static clockid_t posix_clock; + static int posix_clock_set = 0; + + if (! posix_clock_set) { + if (sysconf (_SC_MONOTONIC_CLOCK) >= 0) + posix_clock = CLOCK_MONOTONIC; + else + posix_clock = CLOCK_REALTIME; + posix_clock_set = 1; + } - if (clock_gettime (CLOCK_MONOTONIC, &ts) == -1) { + if (clock_gettime (posix_clock, &ts) == -1) { logger (LOG_ERR, "clock_gettime: %s", strerror (errno)); return (-1); }