X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fcollectd-tg.c;h=7db9fe713ee2dcde8674e2f69aa3827f28295fa2;hb=4d370741101aeb037ae52f3529a4a0869e0dc08a;hp=501567da6ed2db0f4df82c0c60bc1cd8105f4386;hpb=ca299374303452480544ac19e2028b63db362164;p=collectd.git diff --git a/src/collectd-tg.c b/src/collectd-tg.c index 501567da..7db9fe71 100644 --- a/src/collectd-tg.c +++ b/src/collectd-tg.c @@ -28,18 +28,6 @@ # include "config.h" #endif -#ifndef _ISOC99_SOURCE -# define _ISOC99_SOURCE -#endif - -#ifndef _POSIX_C_SOURCE -# define _POSIX_C_SOURCE 200809L -#endif - -#ifndef _XOPEN_SOURCE -# define _XOPEN_SOURCE 700 -#endif - #if !__GNUC__ # define __attribute__(x) /**/ #endif @@ -52,12 +40,12 @@ #include #include #include +#include #include "utils_heap.h" #include "libcollectdclient/collectd/client.h" #include "libcollectdclient/collectd/network.h" -#include "libcollectdclient/collectd/network_buffer.h" #define DEF_NUM_HOSTS 1000 #define DEF_NUM_PLUGINS 20 @@ -112,15 +100,28 @@ static void signal_handler (int signal) /* {{{ */ loop = 0; } /* }}} void signal_handler */ +#if HAVE_CLOCK_GETTIME static double dtime (void) /* {{{ */ { struct timespec ts = { 0 }; if (clock_gettime (CLOCK_MONOTONIC, &ts) != 0) - return NAN; + perror ("clock_gettime"); 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* */ +static double dtime (void) /* {{{ */ +{ + struct timeval tv = { 0 }; + + if (gettimeofday (&tv, /* timezone = */ NULL) != 0) + perror ("gettimeofday"); + + return ((double) tv.tv_sec) + (((double) tv.tv_usec) / 1e6); +} /* }}} double dtime */ +#endif static int compare_time (const void *v0, const void *v1) /* {{{ */ { @@ -154,13 +155,12 @@ static lcc_value_list_t *create_value_list (void) /* {{{ */ lcc_value_list_t *vl; int host_num; - vl = malloc (sizeof (*vl)); + vl = calloc (1, sizeof (*vl)); if (vl == NULL) { - fprintf (stderr, "malloc failed.\n"); + fprintf (stderr, "calloc failed.\n"); return (NULL); } - memset (vl, 0, sizeof (*vl)); vl->values = calloc (/* nmemb = */ 1, sizeof (*vl->values)); if (vl->values == NULL) @@ -199,6 +199,7 @@ static lcc_value_list_t *create_value_list (void) /* {{{ */ strncpy (vl->identifier.type, (vl->values_types[0] == LCC_TYPE_GAUGE) ? "gauge" : "derive", sizeof (vl->identifier.type)); + vl->identifier.type[sizeof (vl->identifier.type) - 1] = 0; snprintf (vl->identifier.type_instance, sizeof (vl->identifier.type_instance), "ti%li", random ()); @@ -336,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; @@ -365,7 +365,7 @@ int main (int argc, char **argv) /* {{{ */ else { lcc_server_t *srv; - + srv = lcc_server_create (net, conf_destination, conf_service); if (srv == NULL) { @@ -382,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; @@ -449,7 +449,6 @@ int main (int argc, char **argv) /* {{{ */ lcc_network_destroy (net); exit (EXIT_SUCCESS); - return (0); } /* }}} int main */ /* vim: set sw=2 sts=2 et fdm=marker : */