X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fstatsd.c;h=9050596f9d3f1894830d479a4d8d09bed27c4c22;hb=48622c3d7c8c0d3ab07cda8a1947c33bfe31df73;hp=28ee337cfb089154c18948ef4f5a482ed8fa8405;hpb=06a86a60a7dabc685bdbd81ce3d36ea5f7e2c2d4;p=collectd.git diff --git a/src/statsd.c b/src/statsd.c index 28ee337c..9050596f 100644 --- a/src/statsd.c +++ b/src/statsd.c @@ -26,10 +26,10 @@ #include "collectd.h" -#include "common.h" #include "plugin.h" -#include "utils_avltree.h" -#include "utils_latency.h" +#include "utils/avltree/avltree.h" +#include "utils/common/common.h" +#include "utils/latency/latency.h" #include #include @@ -352,9 +352,8 @@ static int statsd_handle_set(char const *name, /* {{{ */ status = c_avl_insert(metric->set, set_key, /* value = */ NULL); if (status < 0) { pthread_mutex_unlock(&metrics_lock); - if (status < 0) - ERROR("statsd plugin: c_avl_insert (\"%s\") failed with status %i.", - set_key, status); + ERROR("statsd plugin: c_avl_insert (\"%s\") failed with status %i.", + set_key, status); sfree(set_key); return -1; } else if (status > 0) /* key already exists */ @@ -490,8 +489,8 @@ static int statsd_network_init(struct pollfd **ret_fds, /* {{{ */ int fd; struct pollfd *tmp; - char dbg_node[NI_MAXHOST]; - char dbg_service[NI_MAXSERV]; + char str_node[NI_MAXHOST]; + char str_service[NI_MAXSERV]; fd = socket(ai_ptr->ai_family, ai_ptr->ai_socktype, ai_ptr->ai_protocol); if (fd < 0) { @@ -499,15 +498,24 @@ static int statsd_network_init(struct pollfd **ret_fds, /* {{{ */ continue; } - getnameinfo(ai_ptr->ai_addr, ai_ptr->ai_addrlen, dbg_node, sizeof(dbg_node), - dbg_service, sizeof(dbg_service), + /* allow multiple sockets to use the same PORT number */ + int yes = 1; + if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes)) == -1) { + ERROR("statsd plugin: setsockopt (reuseaddr): %s", STRERRNO); + close(fd); + continue; + } + + getnameinfo(ai_ptr->ai_addr, ai_ptr->ai_addrlen, str_node, sizeof(str_node), + str_service, sizeof(str_service), NI_DGRAM | NI_NUMERICHOST | NI_NUMERICSERV); - DEBUG("statsd plugin: Trying to bind to [%s]:%s ...", dbg_node, - dbg_service); + DEBUG("statsd plugin: Trying to bind to [%s]:%s ...", str_node, + str_service); status = bind(fd, ai_ptr->ai_addr, ai_ptr->ai_addrlen); if (status != 0) { - ERROR("statsd plugin: bind(2) failed: %s", STRERRNO); + ERROR("statsd plugin: bind(2) to [%s]:%s failed: %s", str_node, + str_service, STRERRNO); close(fd); continue; } @@ -525,6 +533,7 @@ static int statsd_network_init(struct pollfd **ret_fds, /* {{{ */ memset(tmp, 0, sizeof(*tmp)); tmp->fd = fd; tmp->events = POLLIN | POLLPRI; + INFO("statsd plugin: Listening on [%s]:%s.", str_node, str_service); } freeaddrinfo(ai_list); @@ -597,9 +606,8 @@ static int statsd_config_timer_percentile(oconfig_item_t *ci) /* {{{ */ return ERANGE; } - tmp = - realloc(conf_timer_percentile, - sizeof(*conf_timer_percentile) * (conf_timer_percentile_num + 1)); + tmp = realloc(conf_timer_percentile, sizeof(*conf_timer_percentile) * + (conf_timer_percentile_num + 1)); if (tmp == NULL) { ERROR("statsd plugin: realloc failed."); return ENOMEM;