From: Marc Fournier Date: Fri, 14 Nov 2014 21:04:16 +0000 (+0100) Subject: write_redis: avoid passing a float/double to redisCommand() X-Git-Tag: collectd-5.5.0~139^2 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=28f4914d1727c7a5a0dbace945c3b1fadbb0bc91;p=collectd.git write_redis: avoid passing a float/double to redisCommand() ... as it seems to not be well supported by hiredis 0.10.1 on Debian 7.0, leading to a segfault. Storing the string representation in a variable instead is the compromise I found to make the plugin work on this system. --- diff --git a/src/write_redis.c b/src/write_redis.c index 28d475fe..b47650d1 100644 --- a/src/write_redis.c +++ b/src/write_redis.c @@ -57,6 +57,7 @@ static int wr_write (const data_set_t *ds, /* {{{ */ char ident[512]; char key[512]; char value[512]; + char time[24]; size_t value_size; char *value_ptr; int status; @@ -67,6 +68,7 @@ static int wr_write (const data_set_t *ds, /* {{{ */ if (status != 0) return (status); ssnprintf (key, sizeof (key), "collectd/%s", ident); + ssnprintf (time, sizeof (time), "%.9f", CDTIME_T_TO_DOUBLE(vl->time)); memset (value, 0, sizeof (value)); value_size = sizeof (value); @@ -86,7 +88,9 @@ static int wr_write (const data_set_t *ds, /* {{{ */ } \ } while (0) - APPEND ("%.9f:", CDTIME_T_TO_DOUBLE(vl->time)); + APPEND (time); + APPEND (":"); + for (i = 0; i < ds->ds_num; i++) { if (ds->ds[i].type == DS_TYPE_COUNTER) @@ -119,8 +123,7 @@ static int wr_write (const data_set_t *ds, /* {{{ */ } assert (node->conn != NULL); - rr = redisCommand (node->conn, "ZADD %s %.9f %s", key, - CDTIME_T_TO_DOUBLE(vl->time), value); + rr = redisCommand (node->conn, "ZADD %s %s %s", key, time, value); if (rr==NULL) WARNING("ZADD command error. key:%s", key);