diff --git a/src/write_tsdb.c b/src/write_tsdb.c
index ee4db2384a2848b9466b3bbedf155579f3225877..bf49ba5f2b10ea553509dbda92346d4eded8fc51 100644 (file)
--- a/src/write_tsdb.c
+++ b/src/write_tsdb.c
*/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
#include "configfile.h"
#include "utils_cache.h"
-#include <pthread.h>
-#include <sys/socket.h>
#include <netdb.h>
#ifndef WT_DEFAULT_NODE
return 0;
}
- if (cb->send_buf_fill <= 0)
+ if (cb->send_buf_fill == 0)
{
cb->send_buf_init_time = cdtime();
return 0;
static int wt_callback_init(struct wt_callback *cb)
{
- struct addrinfo ai_hints;
struct addrinfo *ai_list;
- struct addrinfo *ai_ptr;
int status;
const char *node = cb->node ? cb->node : WT_DEFAULT_NODE;
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)
}
assert (ai_list != NULL);
- for (ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next)
+ for (struct addrinfo *ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next)
{
cb->sock_fd = socket(ai_ptr->ai_family, ai_ptr->ai_socktype,
ai_ptr->ai_protocol);
if (cb->sock_fd < 0)
continue;
+ set_sock_opts(cb->sock_fd);
+
status = connect(cb->sock_fd, ai_ptr->ai_addr, ai_ptr->ai_addrlen);
if (status != 0)
{
{
int status;
char *temp = NULL;
- char *prefix = "";
+ const char *prefix = "";
const char *meta_prefix = "tsdb_prefix";
if (vl->meta) {
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 */
}
}
- message_len = ssnprintf (message,
+ status = ssnprintf (message,
sizeof(message),
"put %s %.0f %s fqdn=%s %s %s\r\n",
key,
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;
}
char key[10*DATA_MAX_NAME_LEN];
char values[512];
- int status, i;
+ int status;
if (0 != strcmp(ds->type, vl->type))
{
return -1;
}
- for (i = 0; i < ds->ds_num; i++)
+ for (size_t i = 0; i < ds->ds_num; i++)
{
const char *ds_name = NULL;
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;
pthread_mutex_init (&cb->send_lock, NULL);
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
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);
static int wt_config(oconfig_item_t *ci)
{
- int i;
-
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;