From: Roy Marples Date: Thu, 31 Jul 2008 23:43:37 +0000 (+0000) Subject: clock_monotonic now is 0 or 1 depending on if the clock is monotonic. Also, systems... X-Git-Tag: v4.0.2~100 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=37a596da190297812137b740303a33d14633cacc;p=thirdparty%2Fdhcpcd.git clock_monotonic now is 0 or 1 depending on if the clock is monotonic. Also, systems that have headers for monotonic but do not claim support now warn about this. You can build dhcpcd to force a monotonic clock. --- diff --git a/common.c b/common.c index 198ce5b4..9911b345 100644 --- a/common.c +++ b/common.c @@ -47,6 +47,8 @@ # define _PATH_DEVNULL "/dev/null" #endif +int clock_monotonic = 0; + /* Handy routine to read very long lines in text files. * This means we read the whole line and avoid any nasty buffer overflows. */ ssize_t @@ -183,20 +185,32 @@ set_nonblock(int fd) * platforms. */ int -clock_monotonic(struct timeval *tp) +get_monotonic(struct timeval *tp) { #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) { + posix_clock = CLOCK_MONOTONIC; + posix_clock_set = 1; + clock_monotonic = 1; + } +#else if (!posix_clock_set) { - if (sysconf(_SC_MONOTONIC_CLOCK) >= 0) + if (sysconf(_SC_MONOTONIC_CLOCK) >= 0) { posix_clock = CLOCK_MONOTONIC; - else + clock_monotonic = 1; + } else { posix_clock = CLOCK_REALTIME; + logger(LOG_WARNING, "host does not support a monotonic clock"); + } + posix_clock_set = 1; } +#endif if (clock_gettime(posix_clock, &ts) == -1) return -1; @@ -214,7 +228,7 @@ uptime(void) { struct timeval tv; - if (clock_monotonic(&tv) == -1) + if (get_monotonic(&tv) == -1) return -1; return tv.tv_sec; } diff --git a/common.h b/common.h index 755ae6af..25226636 100644 --- a/common.h +++ b/common.h @@ -75,7 +75,8 @@ int close_fds(void); int set_cloexec(int); int set_nonblock(int); ssize_t get_line(char **, size_t *, FILE *); -int clock_monotonic(struct timeval *); +extern int clock_monotonic; +int get_monotonic(struct timeval *); time_t uptime(void); int writepid(int, pid_t); void *xrealloc(void *, size_t);