X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fcollectd.c;h=17905c74f95a674eddee10958077ff43bd44c469;hb=a28ebbb8265605a09f0555d1eb036f50b9a784c8;hp=548a8fdd989c0772cb8b361079cdccbda4377edd;hpb=61c19cc11f325017d0186e9c345b6b4f01a4dc72;p=collectd.git diff --git a/src/collectd.c b/src/collectd.c index 548a8fdd..17905c74 100644 --- a/src/collectd.c +++ b/src/collectd.c @@ -301,6 +301,7 @@ static int do_loop (void) { struct timeval tv_now; struct timeval tv_next; + struct timeval tv_wait; struct timespec ts_wait; while (loop == 0) @@ -331,14 +332,17 @@ static int do_loop (void) return (-1); } - if (timeval_sub_timespec (&tv_next, &tv_now, &ts_wait) != 0) + if (timeval_cmp (tv_next, tv_now, &tv_wait) <= 0) { - WARNING ("Not sleeping because " - "`timeval_sub_timespec' returned " - "non-zero!"); + WARNING ("Not sleeping because the next interval is " + "%i.%06i seconds in the past!", + (int) tv_wait.tv_sec, (int) tv_wait.tv_usec); continue; } + ts_wait.tv_sec = tv_wait.tv_sec; + ts_wait.tv_nsec = (long) (1000 * tv_wait.tv_usec); + while ((loop == 0) && (nanosleep (&ts_wait, &ts_wait) == -1)) { if (errno != EINTR)