static pthread_mutex_t metrics_lock = PTHREAD_MUTEX_INITIALIZER;
static pthread_t network_thread;
-static _Bool network_thread_running = 0;
-static _Bool network_thread_shutdown = 0;
+static bool network_thread_running;
+static bool network_thread_shutdown;
static char *conf_node = NULL;
static char *conf_service = NULL;
-static _Bool conf_delete_counters = 0;
-static _Bool conf_delete_timers = 0;
-static _Bool conf_delete_gauges = 0;
-static _Bool conf_delete_sets = 0;
+static bool conf_delete_counters;
+static bool conf_delete_timers;
+static bool conf_delete_gauges;
+static bool conf_delete_sets;
static double *conf_timer_percentile = NULL;
-static size_t conf_timer_percentile_num = 0;
+static size_t conf_timer_percentile_num;
-static _Bool conf_counter_sum = 0;
-static _Bool conf_timer_lower = 0;
-static _Bool conf_timer_upper = 0;
-static _Bool conf_timer_sum = 0;
-static _Bool conf_timer_count = 0;
+static bool conf_counter_sum;
+static bool conf_timer_lower;
+static bool conf_timer_upper;
+static bool conf_timer_sum;
+static bool conf_timer_count;
/* Must hold metrics_lock when calling this function. */
static statsd_metric_t *statsd_metric_lookup_unsafe(char const *name, /* {{{ */
status = recv(fd, buffer, sizeof(buffer), /* flags = */ MSG_DONTWAIT);
if (status < 0) {
- char errbuf[1024];
if ((errno == EAGAIN) || (errno == EWOULDBLOCK))
return;
- ERROR("statsd plugin: recv(2) failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("statsd plugin: recv(2) failed: %s", STRERRNO);
return;
}
fd = socket(ai_ptr->ai_family, ai_ptr->ai_socktype, ai_ptr->ai_protocol);
if (fd < 0) {
- char errbuf[1024];
- ERROR("statsd plugin: socket(2) failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("statsd plugin: socket(2) failed: %s", STRERRNO);
continue;
}
status = bind(fd, ai_ptr->ai_addr, ai_ptr->ai_addrlen);
if (status != 0) {
- char errbuf[1024];
- ERROR("statsd plugin: bind(2) failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("statsd plugin: bind(2) failed: %s", STRERRNO);
close(fd);
continue;
}
while (!network_thread_shutdown) {
status = poll(fds, (nfds_t)fds_num, /* timeout = */ -1);
if (status < 0) {
- char errbuf[1024];
if ((errno == EINTR) || (errno == EAGAIN))
continue;
- ERROR("statsd plugin: poll(2) failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("statsd plugin: poll(2) failed: %s", STRERRNO);
break;
}
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;
/* attr = */ NULL, statsd_network_thread,
/* args = */ NULL);
if (status != 0) {
- char errbuf[1024];
pthread_mutex_unlock(&metrics_lock);
- ERROR("statsd plugin: pthread_create failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("statsd plugin: pthread_create failed: %s", STRERRNO);
return status;
}
}
- network_thread_running = 1;
+ network_thread_running = true;
pthread_mutex_unlock(&metrics_lock);
if (metric->type == STATSD_GAUGE)
vl.values[0].gauge = (gauge_t)metric->value;
else if (metric->type == STATSD_TIMER) {
- _Bool have_events = (metric->updates_num > 0);
+ bool have_events = (metric->updates_num > 0);
/* Make sure all timer metrics share the *same* timestamp. */
vl.time = cdtime();
- ssnprintf(vl.type_instance, sizeof(vl.type_instance), "%s-average", name);
+ snprintf(vl.type_instance, sizeof(vl.type_instance), "%s-average", name);
vl.values[0].gauge =
have_events
? CDTIME_T_TO_DOUBLE(latency_counter_get_average(metric->latency))
plugin_dispatch_values(&vl);
if (conf_timer_lower) {
- ssnprintf(vl.type_instance, sizeof(vl.type_instance), "%s-lower", name);
+ snprintf(vl.type_instance, sizeof(vl.type_instance), "%s-lower", name);
vl.values[0].gauge =
have_events
? CDTIME_T_TO_DOUBLE(latency_counter_get_min(metric->latency))
}
if (conf_timer_upper) {
- ssnprintf(vl.type_instance, sizeof(vl.type_instance), "%s-upper", name);
+ snprintf(vl.type_instance, sizeof(vl.type_instance), "%s-upper", name);
vl.values[0].gauge =
have_events
? CDTIME_T_TO_DOUBLE(latency_counter_get_max(metric->latency))
}
if (conf_timer_sum) {
- ssnprintf(vl.type_instance, sizeof(vl.type_instance), "%s-sum", name);
+ snprintf(vl.type_instance, sizeof(vl.type_instance), "%s-sum", name);
vl.values[0].gauge =
have_events
? CDTIME_T_TO_DOUBLE(latency_counter_get_sum(metric->latency))
}
for (size_t i = 0; i < conf_timer_percentile_num; i++) {
- ssnprintf(vl.type_instance, sizeof(vl.type_instance),
- "%s-percentile-%.0f", name, conf_timer_percentile[i]);
+ snprintf(vl.type_instance, sizeof(vl.type_instance), "%s-percentile-%.0f",
+ name, conf_timer_percentile[i]);
vl.values[0].gauge =
have_events ? CDTIME_T_TO_DOUBLE(latency_counter_get_percentile(
metric->latency, conf_timer_percentile[i]))
* vl.type's above are implicitly set to "latency". */
if (conf_timer_count) {
sstrncpy(vl.type, "gauge", sizeof(vl.type));
- ssnprintf(vl.type_instance, sizeof(vl.type_instance), "%s-count", name);
+ snprintf(vl.type_instance, sizeof(vl.type_instance), "%s-count", name);
vl.values[0].gauge = latency_counter_get_num(metric->latency);
plugin_dispatch_values(&vl);
}
void *value;
if (network_thread_running) {
- network_thread_shutdown = 1;
+ network_thread_shutdown = true;
pthread_kill(network_thread, SIGTERM);
pthread_join(network_thread, /* retval = */ NULL);
}
- network_thread_running = 0;
+ network_thread_running = false;
pthread_mutex_lock(&metrics_lock);