From: Florian Forster Date: Tue, 21 Nov 2017 09:38:52 +0000 (+0100) Subject: Merge branch 'collectd-5.7' into collectd-5.8 X-Git-Url: https://git.octo.it/?p=collectd.git;a=commitdiff_plain;h=65bdbbfb9c6b287de835e5aa81faee8cd864c1e9;hp=cd5f6ba73aff5e086f4edc0acf38a2a6486cba6b Merge branch 'collectd-5.7' into collectd-5.8 --- diff --git a/src/gps.c b/src/gps.c index ecb4bbaa..1d32d049 100644 --- a/src/gps.c +++ b/src/gps.c @@ -26,10 +26,10 @@ * Marc Fournier **/ +#include "collectd.h" #include "common.h" #include "plugin.h" #include "utils_time.h" -#include "collectd.h" #define CGPS_TRUE 1 #define CGPS_FALSE 0 @@ -80,7 +80,7 @@ static int cgps_thread_pause(cdtime_t pTime) { int ret = !cgps_thread_shutdown; - pthread_mutex_lock(&cgps_thread_lock); + pthread_mutex_unlock(&cgps_thread_lock); return ret; } diff --git a/src/table.c b/src/table.c index 5fb51512..7cae3f79 100644 --- a/src/table.c +++ b/src/table.c @@ -169,16 +169,13 @@ static int tbl_config_append_array_i(char *name, size_t **var, size_t *len, } /* tbl_config_append_array_s */ static int tbl_config_result(tbl_t *tbl, oconfig_item_t *ci) { - tbl_result_t *res; - - int status = 0; - if (0 != ci->values_num) { log_err(" does not expect any arguments."); return 1; } - res = realloc(tbl->results, (tbl->results_num + 1) * sizeof(*tbl->results)); + tbl_result_t *res = + realloc(tbl->results, (tbl->results_num + 1) * sizeof(*tbl->results)); if (res == NULL) { char errbuf[1024]; log_err("realloc failed: %s.", sstrerror(errno, errbuf, sizeof(errbuf))); @@ -186,9 +183,8 @@ static int tbl_config_result(tbl_t *tbl, oconfig_item_t *ci) { } tbl->results = res; - ++tbl->results_num; - res = tbl->results + tbl->results_num - 1; + res = tbl->results + tbl->results_num; tbl_result_setup(res); for (int i = 0; i < ci->children_num; ++i) { @@ -209,39 +205,35 @@ static int tbl_config_result(tbl_t *tbl, oconfig_item_t *ci) { c->key); } + int status = 0; if (NULL == res->type) { - log_err("No \"Type\" option specified for " - "in table \"%s\".", + log_err("No \"Type\" option specified for in table \"%s\".", tbl->file); status = 1; } if (NULL == res->values) { - log_err("No \"ValuesFrom\" option specified for " - "in table \"%s\".", + log_err("No \"ValuesFrom\" option specified for in table \"%s\".", tbl->file); status = 1; } if (0 != status) { tbl_result_clear(res); - --tbl->results_num; return status; } + + tbl->results_num++; return 0; } /* tbl_config_result */ static int tbl_config_table(oconfig_item_t *ci) { - tbl_t *tbl; - - int status = 0; - if ((1 != ci->values_num) || (OCONFIG_TYPE_STRING != ci->values[0].type)) { log_err(" expects a single string argument."); return 1; } - tbl = realloc(tables, (tables_num + 1) * sizeof(*tables)); + tbl_t *tbl = realloc(tables, (tables_num + 1) * sizeof(*tables)); if (NULL == tbl) { char errbuf[1024]; log_err("realloc failed: %s.", sstrerror(errno, errbuf, sizeof(errbuf))); @@ -249,9 +241,8 @@ static int tbl_config_table(oconfig_item_t *ci) { } tables = tbl; - ++tables_num; - tbl = tables + tables_num - 1; + tbl = tables + tables_num; tbl_setup(tbl, ci->values[0].value.string); for (size_t i = 0; i < ((size_t)ci->children_num); ++i) { @@ -271,6 +262,7 @@ static int tbl_config_table(oconfig_item_t *ci) { c->key, tbl->file); } + int status = 0; if (NULL == tbl->sep) { log_err("Table \"%s\" does not specify any separator.", tbl->file); status = 1; @@ -284,13 +276,13 @@ static int tbl_config_table(oconfig_item_t *ci) { } if (NULL == tbl->results) { + assert(tbl->results_num == 0); log_err("Table \"%s\" does not specify any (valid) results.", tbl->file); status = 1; } if (0 != status) { tbl_clear(tbl); - --tables_num; return status; } @@ -305,6 +297,8 @@ static int tbl_config_table(oconfig_item_t *ci) { if (res->values[j] > tbl->max_colnum) tbl->max_colnum = res->values[j]; } + + tables_num++; return 0; } /* tbl_config_table */ diff --git a/src/target_set.c b/src/target_set.c index 33ab96c9..47e2d293 100644 --- a/src/target_set.c +++ b/src/target_set.c @@ -184,11 +184,12 @@ static void ts_subst(char *dest, size_t size, const char *string, /* {{{ */ if (vl->meta != NULL) { char **meta_toc = NULL; - int meta_entries = meta_data_toc(vl->meta, &meta_toc); - if (meta_entries <= 0) + int status = meta_data_toc(vl->meta, &meta_toc); + if (status <= 0) return; + size_t meta_entries = (size_t)status; - for (int i = 0; i < meta_entries; i++) { + for (size_t i = 0; i < meta_entries; i++) { char meta_name[DATA_MAX_NAME_LEN]; char *value_str; const char *key = meta_toc[i]; @@ -342,7 +343,6 @@ static int ts_invoke(const data_set_t *ds, value_list_t *vl, /* {{{ */ if (data->meta != NULL) { char temp[DATA_MAX_NAME_LEN * 2]; - int meta_entries; char **meta_toc; if ((new_meta = meta_data_create()) == NULL) { @@ -350,8 +350,14 @@ static int ts_invoke(const data_set_t *ds, value_list_t *vl, /* {{{ */ return -ENOMEM; } - meta_entries = meta_data_toc(data->meta, &meta_toc); - for (int i = 0; i < meta_entries; i++) { + int status = meta_data_toc(data->meta, &meta_toc); + if (status < 0) { + ERROR("Target `set': meta_data_toc failed with status %d.", status); + return status; + } + size_t meta_entries = (size_t)status; + + for (size_t i = 0; i < meta_entries; i++) { const char *key = meta_toc[i]; char *string; int status; @@ -360,7 +366,7 @@ static int ts_invoke(const data_set_t *ds, value_list_t *vl, /* {{{ */ if (status) { ERROR("Target `set': Unable to get replacement metadata value `%s'.", key); - strarray_free(meta_toc, (size_t)meta_entries); + strarray_free(meta_toc, meta_entries); meta_data_destroy(new_meta); return status; } @@ -376,13 +382,13 @@ static int ts_invoke(const data_set_t *ds, value_list_t *vl, /* {{{ */ status = meta_data_add_string(new_meta, key, temp); if (status) { ERROR("Target `set': Unable to set metadata value `%s'.", key); - strarray_free(meta_toc, (size_t)meta_entries); + strarray_free(meta_toc, meta_entries); meta_data_destroy(new_meta); return status; } } - strarray_free(meta_toc, (size_t)meta_entries); + strarray_free(meta_toc, meta_entries); } #define SUBST_FIELD(f) \ diff --git a/src/utils_format_json.c b/src/utils_format_json.c index 53a38b89..4ecbfbe2 100644 --- a/src/utils_format_json.c +++ b/src/utils_format_json.c @@ -500,6 +500,14 @@ static int json_add_string(yajl_gen g, char const *str) /* {{{ */ } \ } while (0) +#define CHECK_SUCCESS(cmd) \ + do { \ + yajl_gen_status s = (cmd); \ + if (s != yajl_gen_status_ok) { \ + return (int)s; \ + } \ + } while (0) + static int format_json_meta(yajl_gen g, notification_meta_t *meta) /* {{{ */ { if (meta == NULL) @@ -525,7 +533,7 @@ static int format_json_meta(yajl_gen g, notification_meta_t *meta) /* {{{ */ default: ERROR("format_json_meta: unknown meta data type %d (name \"%s\")", meta->type, meta->name); - yajl_gen_null(g); + CHECK_SUCCESS(yajl_gen_null(g)); } return format_json_meta(g, meta->next); @@ -544,14 +552,14 @@ static int format_time(yajl_gen g, cdtime_t t) /* {{{ */ static int format_alert(yajl_gen g, notification_t const *n) /* {{{ */ { - yajl_gen_array_open(g); - yajl_gen_map_open(g); /* BEGIN alert */ + CHECK_SUCCESS(yajl_gen_array_open(g)); /* BEGIN array */ + CHECK_SUCCESS(yajl_gen_map_open(g)); /* BEGIN alert */ /* * labels */ JSON_ADD(g, "labels"); - yajl_gen_map_open(g); /* BEGIN labels */ + CHECK_SUCCESS(yajl_gen_map_open(g)); /* BEGIN labels */ JSON_ADD(g, "alertname"); if (strncmp(n->plugin, n->type, strlen(n->plugin)) == 0) @@ -587,27 +595,30 @@ static int format_alert(yajl_gen g, notification_t const *n) /* {{{ */ JSON_ADD(g, "service"); JSON_ADD(g, "collectd"); - yajl_gen_map_close(g); /* END labels */ + CHECK_SUCCESS(yajl_gen_map_close(g)); /* END labels */ /* * annotations */ JSON_ADD(g, "annotations"); - yajl_gen_map_open(g); /* BEGIN annotations */ + CHECK_SUCCESS(yajl_gen_map_open(g)); /* BEGIN annotations */ JSON_ADD(g, "summary"); JSON_ADD(g, n->message); - if (format_json_meta(g, n->meta) != 0) + if (format_json_meta(g, n->meta) != 0) { return -1; + } - yajl_gen_map_close(g); /* END annotations */ + CHECK_SUCCESS(yajl_gen_map_close(g)); /* END annotations */ JSON_ADD(g, "startsAt"); - format_time(g, n->time); + if (format_time(g, n->time) != 0) { + return -1; + } - yajl_gen_map_close(g); /* END alert */ - yajl_gen_array_close(g); + CHECK_SUCCESS(yajl_gen_map_close(g)); /* END alert */ + CHECK_SUCCESS(yajl_gen_array_close(g)); /* END array */ return 0; } /* }}} format_alert */ @@ -672,7 +683,11 @@ int format_json_notification(char *buffer, size_t buffer_size, /* {{{ */ } /* copy to output buffer */ - yajl_gen_get_buf(g, &out, &unused_out_len); + if (yajl_gen_get_buf(g, &out, &unused_out_len) != yajl_gen_status_ok) { + yajl_gen_clear(g); + yajl_gen_free(g); + return -1; + } sstrncpy(buffer, (void *)out, buffer_size); yajl_gen_clear(g); diff --git a/src/write_graphite.c b/src/write_graphite.c index a8d13206..7d7c0e8f 100644 --- a/src/write_graphite.c +++ b/src/write_graphite.c @@ -312,6 +312,7 @@ static void wg_callback_free(void *data) { sfree(cb->prefix); sfree(cb->postfix); + pthread_mutex_unlock(&cb->send_lock); pthread_mutex_destroy(&cb->send_lock); sfree(cb); diff --git a/src/write_sensu.c b/src/write_sensu.c index ce23e654..bd7a56d0 100644 --- a/src/write_sensu.c +++ b/src/write_sensu.c @@ -28,14 +28,15 @@ #include "collectd.h" +#include "common.h" +#include "plugin.h" +#include "utils_cache.h" + #include #include #include #include #include -#include "common.h" -#include "plugin.h" -#include "utils_cache.h" #include #define SENSU_HOST "localhost" @@ -998,7 +999,10 @@ static void sensu_free(void *p) /* {{{ */ sfree(host->separator); free_str_list(&(host->metric_handlers)); free_str_list(&(host->notification_handlers)); + + pthread_mutex_unlock(&host->lock); pthread_mutex_destroy(&host->lock); + sfree(host); } /* }}} void sensu_free */ diff --git a/src/write_tsdb.c b/src/write_tsdb.c index eb6ceb3f..5c43eda3 100644 --- a/src/write_tsdb.c +++ b/src/write_tsdb.c @@ -279,6 +279,7 @@ static void wt_callback_free(void *data) { sfree(cb->service); sfree(cb->host_tags); + pthread_mutex_unlock(&cb->send_lock); pthread_mutex_destroy(&cb->send_lock); sfree(cb);