collectd-tg: Fix sleep interval.
[collectd.git] / src / collectd-tg.c
index 513d4ff..273265c 100644 (file)
@@ -337,7 +337,6 @@ static int read_options (int argc, char **argv) /* {{{ */
 
 int main (int argc, char **argv) /* {{{ */
 {
-  int i;
   double last_time;
   int values_sent = 0;
 
@@ -383,7 +382,7 @@ int main (int argc, char **argv) /* {{{ */
 
   fprintf (stdout, "Creating %i values ... ", conf_num_values);
   fflush (stdout);
-  for (i = 0; i < conf_num_values; i++)
+  for (int i = 0; i < conf_num_values; i++)
   {
     lcc_value_list_t *vl;
 
@@ -415,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 ();