From 28f4914d1727c7a5a0dbace945c3b1fadbb0bc91 Mon Sep 17 00:00:00 2001 From: Marc Fournier Date: Fri, 14 Nov 2014 22:04:16 +0100 Subject: [PATCH] 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. --- src/write_redis.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) 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); -- 2.11.0