summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 1326af3)
raw | patch | inline | side by side (parent: 1326af3)
author | Florian Forster <octo@collectd.org> | |
Fri, 11 Nov 2016 13:34:20 +0000 (14:34 +0100) | ||
committer | Florian Forster <octo@collectd.org> | |
Fri, 11 Nov 2016 13:36:15 +0000 (14:36 +0100) |
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.
block for years. This correctly subtracts "now" from the metric's time
and only sleeps for the duration between the two.
src/collectd-tg.c | patch | blob | history |
diff --git a/src/collectd-tg.c b/src/collectd-tg.c
index 7db9fe713ee2dcde8674e2f69aa3827f28295fa2..273265c338e32ac88833a15a8e758c8529b54607 100644 (file)
--- a/src/collectd-tg.c
+++ b/src/collectd-tg.c
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 ();