X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Frrdcached.c;h=6d45ac9fdf5287644edae598a4f2912a03686439;hb=8c5927c52f4eefebaad3a6ecadc253ee9007ebb5;hp=42fd3a34414969b139d8b0086c3016ebd7603f7b;hpb=3933d0a0e2a8887b40c77ac0a92c1cac79f9b4a1;p=collectd.git diff --git a/src/rrdcached.c b/src/rrdcached.c index 42fd3a34..6d45ac9f 100644 --- a/src/rrdcached.c +++ b/src/rrdcached.c @@ -25,6 +25,7 @@ **/ #include "collectd.h" + #include "plugin.h" #include "common.h" #include "utils_rrdcreate.h" @@ -69,7 +70,6 @@ static int value_list_to_string (char *buffer, int buffer_len, { int offset; int status; - int i; time_t t; assert (0 == strcmp (ds->type, vl->type)); @@ -82,7 +82,7 @@ static int value_list_to_string (char *buffer, int buffer_len, return (-1); offset = status; - for (i = 0; i < ds->ds_num; i++) + for (size_t i = 0; i < ds->ds_num; i++) { if ((ds->ds[i].type != DS_TYPE_COUNTER) && (ds->ds[i].type != DS_TYPE_GAUGE) @@ -95,7 +95,7 @@ static int value_list_to_string (char *buffer, int buffer_len, status = ssnprintf (buffer + offset, buffer_len - offset, ":%llu", vl->values[i].counter); } - else if (ds->ds[i].type == DS_TYPE_GAUGE) + else if (ds->ds[i].type == DS_TYPE_GAUGE) { status = ssnprintf (buffer + offset, buffer_len - offset, ":%f", vl->values[i].gauge); @@ -107,7 +107,7 @@ static int value_list_to_string (char *buffer, int buffer_len, else /* if (ds->ds[i].type == DS_TYPE_ABSOLUTE) */ { status = ssnprintf (buffer + offset, buffer_len - offset, ":%"PRIu64, vl->values[i].absolute); - + } if ((status < 1) || (status >= (buffer_len - offset))) @@ -217,9 +217,7 @@ static int rc_config_add_timespan (int timespan) static int rc_config (oconfig_item_t *ci) { - int i; - - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t const *child = ci->children + i; const char *key = child->key; @@ -313,11 +311,11 @@ static int rc_read (void) { int status; rrdc_stats_t *head; - rrdc_stats_t *ptr; _Bool retried = 0; - value_t values[1]; value_list_t vl = VALUE_LIST_INIT; + vl.values = &(value_t) { .gauge = NAN }; + vl.values_len = 1; if (daemon_address == NULL) return (-1); @@ -325,13 +323,8 @@ static int rc_read (void) if (!config_collect_stats) return (-1); - vl.values = values; - vl.values_len = 1; - - if ((strncmp ("unix:", daemon_address, strlen ("unix:")) == 0) - || (daemon_address[0] == '/')) - sstrncpy (vl.host, hostname_g, sizeof (vl.host)); - else + if ((strncmp ("unix:", daemon_address, strlen ("unix:")) != 0) + && (daemon_address[0] != '/')) sstrncpy (vl.host, daemon_address, sizeof (vl.host)); sstrncpy (vl.plugin, "rrdcached", sizeof (vl.plugin)); @@ -354,7 +347,7 @@ static int rc_read (void) if (status == 0) break; - if (! retried) + if (!retried) { retried = 1; if (try_reconnect () == 0) @@ -367,12 +360,12 @@ static int rc_read (void) return (-1); } - for (ptr = head; ptr != NULL; ptr = ptr->next) + for (rrdc_stats_t *ptr = head; ptr != NULL; ptr = ptr->next) { if (ptr->type == RRDC_STATS_TYPE_GAUGE) - values[0].gauge = (gauge_t) ptr->value.gauge; + vl.values[0].gauge = (gauge_t) ptr->value.gauge; else if (ptr->type == RRDC_STATS_TYPE_COUNTER) - values[0].counter = (counter_t) ptr->value.counter; + vl.values[0].counter = (counter_t) ptr->value.counter; else continue; @@ -526,7 +519,7 @@ static int rc_write (const data_set_t *ds, const value_list_t *vl, if (status == 0) break; - if (! retried) + if (!retried) { retried = 1; if (try_reconnect () == 0) @@ -576,7 +569,7 @@ static int rc_flush (__attribute__((unused)) cdtime_t timeout, /* {{{ */ if (status == 0) break; - if (! retried) + if (!retried) { retried = 1; if (try_reconnect () == 0)