From: Florian Forster Date: Fri, 11 Nov 2016 13:34:20 +0000 (+0100) Subject: collectd-tg: Fix sleep interval. X-Git-Tag: collectd-5.6.2~9 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=db961f476426f5dd3ca1663ffc094f0fc7f6f8a2;p=collectd.git collectd-tg: Fix sleep interval. nanosleep() was called with the current time, meaning that it would block for years. This correctly subtracts "now" from the metric's time and only sleeps for the duration between the two. --- diff --git a/src/collectd-tg.c b/src/collectd-tg.c index 7db9fe71..273265c3 100644 --- a/src/collectd-tg.c +++ b/src/collectd-tg.c @@ -414,11 +414,11 @@ int main (int argc, char **argv) /* {{{ */ while (now < vl->time) { - /* 1 / 100 second */ - struct timespec ts = { 0, 10000000 }; - - ts.tv_sec = (time_t) now; - ts.tv_nsec = (long) ((now - ((double) ts.tv_sec)) * 1e9); + double diff = vl->time - now; + struct timespec ts = { + .tv_sec = (time_t) diff, + }; + ts.tv_nsec = (long) ((diff - ((double) ts.tv_sec)) * 1e9); nanosleep (&ts, /* remaining = */ NULL); now = dtime ();