X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fwrite_tsdb.c;h=78166b180f34a3b8f05abc33258ea82b549033ef;hb=f3610533206238bf4fcb72c76e9a07517d8bc64b;hp=ee4db2384a2848b9466b3bbedf155579f3225877;hpb=e0e307657d6b751d6beb5afb92c9359a6df7f5e8;p=collectd.git diff --git a/src/write_tsdb.c b/src/write_tsdb.c index ee4db238..78166b18 100644 --- a/src/write_tsdb.c +++ b/src/write_tsdb.c @@ -42,14 +42,13 @@ */ #include "collectd.h" + #include "common.h" #include "plugin.h" #include "configfile.h" #include "utils_cache.h" -#include -#include #include #ifndef WT_DEFAULT_NODE @@ -143,7 +142,7 @@ static int wt_flush_nolock(cdtime_t timeout, struct wt_callback *cb) return 0; } - if (cb->send_buf_fill <= 0) + if (cb->send_buf_fill == 0) { cb->send_buf_init_time = cdtime(); return 0; @@ -157,7 +156,6 @@ static int wt_flush_nolock(cdtime_t timeout, struct wt_callback *cb) static int wt_callback_init(struct wt_callback *cb) { - struct addrinfo ai_hints; struct addrinfo *ai_list; struct addrinfo *ai_ptr; int status; @@ -168,14 +166,11 @@ static int wt_callback_init(struct wt_callback *cb) if (cb->sock_fd > 0) return 0; - memset(&ai_hints, 0, sizeof(ai_hints)); -#ifdef AI_ADDRCONFIG - ai_hints.ai_flags |= AI_ADDRCONFIG; -#endif - ai_hints.ai_family = AF_UNSPEC; - ai_hints.ai_socktype = SOCK_STREAM; - - ai_list = NULL; + struct addrinfo ai_hints = { + .ai_family = AF_UNSPEC, + .ai_flags = AI_ADDRCONFIG, + .ai_socktype = SOCK_STREAM + }; status = getaddrinfo(node, service, &ai_hints, &ai_list); if (status != 0) @@ -347,7 +342,7 @@ static int wt_format_name(char *ret, int ret_len, { int status; char *temp = NULL; - char *prefix = ""; + const char *prefix = ""; const char *meta_prefix = "tsdb_prefix"; if (vl->meta) { @@ -410,11 +405,11 @@ static int wt_send_message (const char* key, const char* value, const char* host, meta_data_t *md) { int status; - int message_len; + size_t message_len; char *temp = NULL; - char *tags = ""; + const char *tags = ""; char message[1024]; - char *host_tags = cb->host_tags ? cb->host_tags : ""; + const char *host_tags = cb->host_tags ? cb->host_tags : ""; const char *meta_tsdb = "tsdb_tags"; /* skip if value is NaN */ @@ -435,7 +430,7 @@ static int wt_send_message (const char* key, const char* value, } } - message_len = ssnprintf (message, + status = ssnprintf (message, sizeof(message), "put %s %.0f %s fqdn=%s %s %s\r\n", key, @@ -444,12 +439,14 @@ static int wt_send_message (const char* key, const char* value, host, tags, host_tags); - sfree(temp); + if (status < 0) + return -1; + message_len = (size_t) status; if (message_len >= sizeof(message)) { ERROR("write_tsdb plugin: message buffer too small: " - "Need %d bytes.", message_len + 1); + "Need %zu bytes.", message_len + 1); return -1; } @@ -505,7 +502,8 @@ static int wt_write_messages(const data_set_t *ds, const value_list_t *vl, char key[10*DATA_MAX_NAME_LEN]; char values[512]; - int status, i; + int status; + size_t i; if (0 != strcmp(ds->type, vl->type)) { @@ -573,17 +571,16 @@ static int wt_write(const data_set_t *ds, const value_list_t *vl, static int wt_config_tsd(oconfig_item_t *ci) { struct wt_callback *cb; - user_data_t user_data; + user_data_t user_data = { 0 }; char callback_name[DATA_MAX_NAME_LEN]; int i; - cb = malloc(sizeof(*cb)); + cb = calloc(1, sizeof(*cb)); if (cb == NULL) { - ERROR("write_tsdb plugin: malloc failed."); + ERROR("write_tsdb plugin: calloc failed."); return -1; } - memset(cb, 0, sizeof(*cb)); cb->sock_fd = -1; cb->node = NULL; cb->service = NULL; @@ -617,7 +614,6 @@ static int wt_config_tsd(oconfig_item_t *ci) cb->node != NULL ? cb->node : WT_DEFAULT_NODE, cb->service != NULL ? cb->service : WT_DEFAULT_SERVICE); - memset(&user_data, 0, sizeof(user_data)); user_data.data = cb; user_data.free_func = wt_callback_free; plugin_register_write(callback_name, wt_write, &user_data);