X-Git-Url: https://git.octo.it/?a=blobdiff_plain;ds=sidebyside;f=src%2Fcollectd-tg.c;h=23257fde9b2eaefbc52a063ad6b1cfad39843dc9;hb=6019ea134e7c1939d9e875cc0c28f2ac6f454647;hp=80473e0ef79816fe53becb2ab41f4f86c5c86715;hpb=06efe4f50bbdfbade922b8a3ee4576eb2cc4562c;p=collectd.git diff --git a/src/collectd-tg.c b/src/collectd-tg.c index 80473e0e..23257fde 100644 --- a/src/collectd-tg.c +++ b/src/collectd-tg.c @@ -40,6 +40,7 @@ #include #include #include +#include #include "utils_heap.h" @@ -100,6 +101,7 @@ static void signal_handler (int signal) /* {{{ */ loop = 0; } /* }}} void signal_handler */ +#if HAVE_CLOCK_GETTIME static double dtime (void) /* {{{ */ { struct timespec ts = { 0 }; @@ -109,6 +111,18 @@ static double dtime (void) /* {{{ */ 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) /* {{{ */ { @@ -142,13 +156,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) @@ -187,6 +200,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 ()); @@ -353,7 +367,7 @@ int main (int argc, char **argv) /* {{{ */ else { lcc_server_t *srv; - + srv = lcc_server_create (net, conf_destination, conf_service); if (srv == NULL) {