X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fwrite_tsdb.c;h=46028ba161b558e357641577a3e2daff14b79cc2;hb=72a76347831a848e6722d9147297a1e03c4c01d8;hp=ee4db2384a2848b9466b3bbedf155579f3225877;hpb=f7f5868ee0378791ccd8d1788e27ebf2a02737dc;p=collectd.git diff --git a/src/write_tsdb.c b/src/write_tsdb.c index ee4db238..46028ba1 100644 --- a/src/write_tsdb.c +++ b/src/write_tsdb.c @@ -49,7 +49,6 @@ #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; @@ -347,7 +346,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 +409,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 +434,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 +443,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 +506,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)) { @@ -577,13 +579,12 @@ static int wt_config_tsd(oconfig_item_t *ci) 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;