Merge branch 'collectd-5.7' into collectd-5.8
[collectd.git] / src / collectd-tg.c
index 71f6040..48f2dc4 100644 (file)
@@ -44,8 +44,8 @@
 
 #include "utils_heap.h"
 
-#include "libcollectdclient/collectd/client.h"
-#include "libcollectdclient/collectd/network.h"
+#include "collectd/client.h"
+#include "collectd/network.h"
 
 #define DEF_NUM_HOSTS 1000
 #define DEF_NUM_PLUGINS 20
@@ -107,7 +107,7 @@ static double dtime(void) /* {{{ */
   if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0)
     perror("clock_gettime");
 
-  return ((double)ts.tv_sec) + (((double)ts.tv_nsec) / 1e9);
+  return (double)ts.tv_sec + (double)ts.tv_nsec / 1e9;
 } /* }}} double dtime */
 #else
 /* Work around for Mac OS X which doesn't have clock_gettime(2). *sigh* */
@@ -118,7 +118,7 @@ static double dtime(void) /* {{{ */
   if (gettimeofday(&tv, /* timezone = */ NULL) != 0)
     perror("gettimeofday");
 
-  return ((double)tv.tv_sec) + (((double)tv.tv_usec) / 1e6);
+  return (double)tv.tv_sec + ((double)tv.tv_usec) / 1e6;
 } /* }}} double dtime */
 #endif
 
@@ -128,11 +128,11 @@ static int compare_time(const void *v0, const void *v1) /* {{{ */
   const lcc_value_list_t *vl1 = v1;
 
   if (vl0->time < vl1->time)
-    return (-1);
+    return -1;
   else if (vl0->time > vl1->time)
-    return (1);
+    return 1;
   else
-    return (0);
+    return 0;
 } /* }}} int compare_time */
 
 static int get_boundet_random(int min, int max) /* {{{ */
@@ -140,14 +140,13 @@ static int get_boundet_random(int min, int max) /* {{{ */
   int range;
 
   if (min >= max)
-    return (-1);
+    return -1;
   if (min == (max - 1))
-    return (min);
+    return min;
 
   range = max - min;
 
-  return (min + ((int)(((double)range) * ((double)random()) /
-                       (((double)RAND_MAX) + 1.0))));
+  return min + ((int)(((double)range) * ((double)random()) / (((double)RAND_MAX) + 1.0)));
 } /* }}} int get_boundet_random */
 
 static lcc_value_list_t *create_value_list(void) /* {{{ */
@@ -158,14 +157,14 @@ static lcc_value_list_t *create_value_list(void) /* {{{ */
   vl = calloc(1, sizeof(*vl));
   if (vl == NULL) {
     fprintf(stderr, "calloc failed.\n");
-    return (NULL);
+    return NULL;
   }
 
   vl->values = calloc(/* nmemb = */ 1, sizeof(*vl->values));
   if (vl->values == NULL) {
     fprintf(stderr, "calloc failed.\n");
     free(vl);
-    return (NULL);
+    return NULL;
   }
 
   vl->values_types = calloc(/* nmemb = */ 1, sizeof(*vl->values_types));
@@ -173,7 +172,7 @@ static lcc_value_list_t *create_value_list(void) /* {{{ */
     fprintf(stderr, "calloc failed.\n");
     free(vl->values);
     free(vl);
-    return (NULL);
+    return NULL;
   }
 
   vl->values_len = 1;
@@ -199,7 +198,7 @@ static lcc_value_list_t *create_value_list(void) /* {{{ */
   snprintf(vl->identifier.type_instance, sizeof(vl->identifier.type_instance),
            "ti%li", random());
 
-  return (vl);
+  return vl;
 } /* }}} int create_value_list */
 
 static void destroy_value_list(lcc_value_list_t *vl) /* {{{ */
@@ -228,7 +227,7 @@ static int send_value(lcc_value_list_t *vl) /* {{{ */
 
   vl->time += vl->interval;
 
-  return (0);
+  return 0;
 } /* }}} int send_value */
 
 static int get_integer_opt(const char *str, int *ret_value) /* {{{ */
@@ -252,7 +251,7 @@ static int get_integer_opt(const char *str, int *ret_value) /* {{{ */
   }
 
   *ret_value = tmp;
-  return (0);
+  return 0;
 } /* }}} int get_integer_opt */
 
 static int get_double_opt(const char *str, double *ret_value) /* {{{ */
@@ -276,7 +275,7 @@ static int get_double_opt(const char *str, double *ret_value) /* {{{ */
   }
 
   *ret_value = tmp;
-  return (0);
+  return 0;
 } /* }}} int get_double_opt */
 
 static int read_options(int argc, char **argv) /* {{{ */
@@ -317,7 +316,7 @@ static int read_options(int argc, char **argv) /* {{{ */
     } /* switch (opt) */
   }   /* while (getopt) */
 
-  return (0);
+  return 0;
 } /* }}} int read_options */
 
 int main(int argc, char **argv) /* {{{ */
@@ -388,11 +387,11 @@ int main(int argc, char **argv) /* {{{ */
       double now = dtime();
 
       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();
@@ -423,5 +422,3 @@ int main(int argc, char **argv) /* {{{ */
   lcc_network_destroy(net);
   exit(EXIT_SUCCESS);
 } /* }}} int main */
-
-/* vim: set sw=2 sts=2 et fdm=marker : */