]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
clock_monotonic now is 0 or 1 depending on if the clock is monotonic. Also, systems...
authorRoy Marples <roy@marples.name>
Thu, 31 Jul 2008 23:43:37 +0000 (23:43 +0000)
committerRoy Marples <roy@marples.name>
Thu, 31 Jul 2008 23:43:37 +0000 (23:43 +0000)
common.c
common.h

index 198ce5b4eb8274dbb00af5c9978ad36883db378b..9911b3450ad7c0f341b0d8c9fef80a7062608081 100644 (file)
--- 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;
 }
index 755ae6af03a3d2af8fbf96cda9e6b1329c3afff3..25226636d3b71c896c2af08d7d480e9de2941fff 100644 (file)
--- 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);