From: Florian Forster Date: Tue, 21 Nov 2017 09:39:44 +0000 (+0100) Subject: Merge branch 'collectd-5.8' X-Git-Url: https://git.octo.it/?p=collectd.git;a=commitdiff_plain;h=072244d2e10336241610a1a0448a8149e9c77e7e;hp=6f08f35672576fccfce8f2dc5077d2f3ed73febe Merge branch 'collectd-5.8' --- diff --git a/ChangeLog b/ChangeLog index 86b7cb81..5c7c42f8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,4 @@ -2017-11-15, Version 5.8.0 (RC0) +2017-11-17, Version 5.8.0 * collectd: The core daemon is now completely licensed under the MIT license. * collectd: Added daemon option to avoid making BaseDir. Thanks to 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 80eca959..cfe9a589 100644 --- a/src/table.c +++ b/src/table.c @@ -168,25 +168,21 @@ 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) { log_err("realloc failed: %s.", STRERRNO); return -1; } 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) { @@ -207,48 +203,43 @@ 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) { log_err("realloc failed: %s.", STRERRNO); return -1; } 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) { @@ -268,6 +259,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; @@ -281,13 +273,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; } @@ -302,6 +294,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/utils_ovs.c b/src/utils_ovs.c index 5a8090e3..2df9f2b0 100644 --- a/src/utils_ovs.c +++ b/src/utils_ovs.c @@ -997,9 +997,10 @@ ovs_db_t *ovs_db_init(const char *node, const char *service, return NULL; /* allocate db data & fill it */ - ovs_db_t *pdb = pdb = calloc(1, sizeof(*pdb)); + ovs_db_t *pdb = calloc(1, sizeof(*pdb)); if (pdb == NULL) return NULL; + pdb->sock = -1; /* store the OVS DB address */ sstrncpy(pdb->node, node, sizeof(pdb->node)); @@ -1041,7 +1042,6 @@ ovs_db_t *ovs_db_init(const char *node, const char *service, } /* init polling thread */ - pdb->sock = -1; if (ovs_db_poll_thread_init(pdb) < 0) { ovs_db_destroy(pdb); return NULL; diff --git a/src/write_graphite.c b/src/write_graphite.c index 1aa07f10..c301ae65 100644 --- a/src/write_graphite.c +++ b/src/write_graphite.c @@ -303,6 +303,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 a34f0cf9..ddeecf83 100644 --- a/src/write_sensu.c +++ b/src/write_sensu.c @@ -31,6 +31,7 @@ #include "common.h" #include "plugin.h" #include "utils_cache.h" + #include #include #include @@ -996,7 +997,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 a3b997b4..d5d55987 100644 --- a/src/write_tsdb.c +++ b/src/write_tsdb.c @@ -277,6 +277,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); diff --git a/version-gen.sh b/version-gen.sh index 620f46ea..f16e6616 100755 --- a/version-gen.sh +++ b/version-gen.sh @@ -1,6 +1,6 @@ #!/bin/sh -DEFAULT_VERSION="5.8.0-RC0.git" +DEFAULT_VERSION="5.8.0.git" if [ -d .git ]; then VERSION="`git describe --dirty=+ --abbrev=7 2> /dev/null | grep collectd | sed -e 's/^collectd-//' -e 's/-/./g'`"