From ccc50cef48b33070960993ca72185caf87b070eb Mon Sep 17 00:00:00 2001 From: Pavel Labath Date: Sat, 17 Sep 2011 13:07:16 +0200 Subject: [PATCH] Use monotonic time when calculating the update interval (fixes sf.net #2970255) when the system clock is moved backwards, the update interval would be calculated incorrectly. If it was moved back far enough, conky would use 100% cpu. Conky now uses monotonic clock to prevent this. If it turns out to be unsupported on some platform, an appropriate fallback can be added. problem reported by norsetto --- src/common.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/common.c b/src/common.c index b9b093b6..ddc32dae 100644 --- a/src/common.c +++ b/src/common.c @@ -37,7 +37,7 @@ #include "timeinfo.h" #include #include -#include +#include #include #include #include @@ -92,10 +92,10 @@ int update_uname(void) double get_time(void) { - struct timeval tv; + struct timespec tv; - gettimeofday(&tv, 0); - return tv.tv_sec + (tv.tv_usec / 1000000.0); + clock_gettime(CLOCK_MONOTONIC, &tv); + return tv.tv_sec + (tv.tv_nsec * 1e-9); } /* Converts '~/...' paths to '/home/blah/...' assumes that 'dest' is at least