X-Git-Url: https://git.octo.it/?p=collectd.git;a=blobdiff_plain;f=src%2Fgmond.c;h=03dedcca606249c7b771f7511dd75f5c8a427a9a;hp=ca654194f6d277c9bacc4c2c758aefcd65dca018;hb=54619dc85fd308b21ed09a0271e5c7383c7921b9;hpb=a0412f28fc15eb04a9a630678a97b6bce2d71fb1 diff --git a/src/gmond.c b/src/gmond.c index ca654194..03dedcca 100644 --- a/src/gmond.c +++ b/src/gmond.c @@ -26,9 +26,9 @@ #include "collectd.h" -#include "common.h" #include "plugin.h" -#include "utils_avltree.h" +#include "utils/avltree/avltree.h" +#include "utils/common/common.h" #if HAVE_NETDB_H #include @@ -252,10 +252,8 @@ static int create_sockets(socket_entry_t **ret_sockets, /* {{{ */ sockets_num++; break; } else { - int yes = 1; - status = setsockopt(sockets[sockets_num].fd, SOL_SOCKET, SO_REUSEADDR, - (void *)&yes, sizeof(yes)); + &(int){1}, sizeof(int)); if (status != 0) { WARNING("gmond plugin: setsockopt(2) failed: %s", STRERRNO); } @@ -399,8 +397,8 @@ static staging_entry_t *staging_entry_get(const char *host, /* {{{ */ if (staging_tree == NULL) return NULL; - snprintf(key, sizeof(key), "%s/%s/%s", host, type, - (type_instance != NULL) ? type_instance : ""); + ssnprintf(key, sizeof(key), "%s/%s/%s", host, type, + (type_instance != NULL) ? type_instance : ""); se = NULL; status = c_avl_get(staging_tree, key, (void *)&se); @@ -415,7 +413,7 @@ static staging_entry_t *staging_entry_get(const char *host, /* {{{ */ sstrncpy(se->key, key, sizeof(se->key)); se->flags = 0; - se->vl.values = (value_t *)calloc(values_len, sizeof(*se->vl.values)); + se->vl.values = calloc(values_len, sizeof(*se->vl.values)); if (se->vl.values == NULL) { sfree(se); return NULL; @@ -745,8 +743,8 @@ static void *mc_receive_thread(void *arg) /* {{{ */ return (void *)-1; } - mc_receive_sockets = (struct pollfd *)calloc(mc_receive_sockets_num, - sizeof(*mc_receive_sockets)); + mc_receive_sockets = + calloc(mc_receive_sockets_num, sizeof(*mc_receive_sockets)); if (mc_receive_sockets == NULL) { ERROR("gmond plugin: calloc failed."); for (size_t i = 0; i < mc_receive_sockets_num; i++) @@ -833,28 +831,6 @@ static int mc_receive_thread_stop(void) /* {{{ */ * * */ -static int gmond_config_set_string(oconfig_item_t *ci, char **str) /* {{{ */ -{ - char *tmp; - - if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) { - WARNING("gmond plugin: The `%s' option needs " - "exactly one string argument.", - ci->key); - return -1; - } - - tmp = strdup(ci->values[0].value.string); - if (tmp == NULL) { - ERROR("gmond plugin: strdup failed."); - return -1; - } - - sfree(*str); - *str = tmp; - return 0; -} /* }}} int gmond_config_set_string */ - static int gmond_config_add_metric(oconfig_item_t *ci) /* {{{ */ { metric_map_t *map; @@ -889,11 +865,11 @@ static int gmond_config_add_metric(oconfig_item_t *ci) /* {{{ */ for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; if (strcasecmp("Type", child->key) == 0) - gmond_config_set_string(child, &map->type); + cf_util_get_string(child, &map->type); else if (strcasecmp("TypeInstance", child->key) == 0) - gmond_config_set_string(child, &map->type_instance); + cf_util_get_string(child, &map->type_instance); else if (strcasecmp("DataSource", child->key) == 0) - gmond_config_set_string(child, &map->ds_name); + cf_util_get_string(child, &map->ds_name); else { WARNING("gmond plugin: Unknown configuration option `%s' ignored.", child->key);