From f02fb0e530acdeec827d2016e58bcdedd1837046 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Manuel=20Luis=20Sanmart=C3=ADn=20Rozada?= Date: Wed, 20 May 2015 20:52:58 +0200 Subject: [PATCH] Plugin tail_csv: the manual says that you can use multiple times the Collect option but the code expecs t"Collect n1 n2 n3 n4", fix to allow to put the option Collect multiple times. --- src/tail_csv.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/tail_csv.c b/src/tail_csv.c index 6c3d5f73..4794f82e 100644 --- a/src/tail_csv.c +++ b/src/tail_csv.c @@ -379,7 +379,8 @@ static void tcsv_instance_definition_destroy(void *arg){ static int tcsv_config_add_instance_collect(instance_definition_t *id, oconfig_item_t *ci){ metric_definition_t *metric; - int i; + metric_definition_t **metric_list; + int i,j,n; if (ci->values_num < 1){ WARNING("tail_csv plugin: The `Collect' config option needs at least one argument."); @@ -393,17 +394,20 @@ static int tcsv_config_add_instance_collect(instance_definition_t *id, oconfig_i return (-1); } - id->metric_list = (metric_definition_t **)malloc(sizeof(metric_definition_t *) * ci->values_num); - if (id->metric_list == NULL) + n = id->metric_list_len + ci->values_num; + metric_list = (metric_definition_t **)realloc(id->metric_list, sizeof(metric_definition_t *) * n); + if (metric_list == NULL) return (-1); - for (i = 0; i < ci->values_num; ++i){ + id->metric_list = metric_list; + + for (i = id->metric_list_len, j=0; i < n; ++i, ++j){ for (metric = metric_head; metric != NULL; metric = metric->next) - if (strcasecmp(ci->values[i].value.string, metric->name) == 0) + if (strcasecmp(ci->values[j].value.string, metric->name) == 0) break; if (metric == NULL){ - WARNING("tail_csv plugin: `Collect' argument not found `%s'.", ci->values[i].value.string); + WARNING("tail_csv plugin: `Collect' argument not found `%s'.", ci->values[j].value.string); return (-1); } -- 2.30.2