]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Use sysconf to detect if we have a working monotonic clock.
authorRoy Marples <roy@marples.name>
Mon, 22 Oct 2007 14:32:31 +0000 (14:32 +0000)
committerRoy Marples <roy@marples.name>
Mon, 22 Oct 2007 14:32:31 +0000 (14:32 +0000)
ChangeLog
Makefile
common.c

index d275d47970784d993f99d45ee8de17617d82ffa4..6d2d69d4de01467b80708e93fc7dacb2410cc87d 100644 (file)
--- 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.
 
index bb1f00fcfec49947de3ac2d5dba755efee7cbd42..611e2f818620dcf5cb0e6424634c9f3753476fd8 100644 (file)
--- 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 <time.h>\nint main (void) { struct timespec ts; return (clock_gettime (CLOCK_MONOTONIC, &ts)); }\n' > .clock_gettime.c; \
+_LIBRT_SH = printf '\#include <time.h>\n\#include <unistd.h>\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)
index 1fb5018723558f7d0def081c87474e475873ce4a..45bd89693689de177966be36927503af2f9eb7fd 100644 (file)
--- 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);
        }