1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-12-27 04:32:55 +00:00

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
This commit is contained in:
Pavel Labath 2011-09-17 13:07:16 +02:00
parent 542e0c085e
commit c9a306defd

View File

@ -40,7 +40,7 @@
#include "top.h"
#include <ctype.h>
#include <errno.h>
#include <sys/time.h>
#include <time.h>
#include <sys/ioctl.h>
#include <net/if.h>
#include <netinet/in.h>
@ -101,10 +101,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/...'