X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Ftokyotyrant.c;h=154215f867bcc16ed0c6e4cec866883628c3af6c;hb=c53c496b6db4e11fd8aed8df9556dad481220196;hp=26366c928373aee0c4c12e91d3013d30b34d3c4f;hpb=a86c1a6b695f5f967fb102da12a9f93dcee26ed3;p=collectd.git diff --git a/src/tokyotyrant.c b/src/tokyotyrant.c index 26366c92..154215f8 100644 --- a/src/tokyotyrant.c +++ b/src/tokyotyrant.c @@ -20,14 +20,10 @@ **/ #include "collectd.h" + #include "plugin.h" #include "common.h" #include "utils_cache.h" -#include "utils_parse_option.h" - -#include -#include -#include #include @@ -46,56 +42,6 @@ static char *config_port = NULL; static TCRDB *rdb = NULL; -static int parse_service_name (const char *service_name) -{ - struct addrinfo *ai_list; - struct addrinfo *ai_ptr; - struct addrinfo ai_hints; - int status; - int service_number; - - ai_list = NULL; - memset (&ai_hints, 0, sizeof (ai_hints)); - ai_hints.ai_family = AF_UNSPEC; - - status = getaddrinfo (/* node = */ NULL, service_name, - &ai_hints, &ai_list); - if (status != 0) - { - ERROR ("tokyotyrant plugin: getaddrinfo failed: %s", - gai_strerror (status)); - return (-1); - } - - service_number = -1; - for (ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next) - { - if (ai_ptr->ai_family == AF_INET) - { - struct sockaddr_in *sa; - - sa = (void *) ai_ptr->ai_addr; - service_number = (int) ntohs (sa->sin_port); - } - else if (ai_ptr->ai_family == AF_INET6) - { - struct sockaddr_in6 *sa; - - sa = (void *) ai_ptr->ai_addr; - service_number = (int) ntohs (sa->sin6_port); - } - - if ((service_number > 0) && (service_number <= 65535)) - break; - } - - freeaddrinfo (ai_list); - - if ((service_number > 0) && (service_number <= 65535)) - return (service_number); - return (-1); -} /* int parse_service_name */ - static int tt_config (const char *key, const char *value) { if (strcasecmp ("Host", key) == 0) @@ -133,22 +79,19 @@ static int tt_config (const char *key, const char *value) return (0); } -static void printerr() +static void printerr (void) { int ecode = tcrdbecode(rdb); ERROR ("tokyotyrant plugin: error: %d, %s", ecode, tcrdberrmsg(ecode)); } -static void tt_submit (gauge_t val, const char* type) +static void tt_submit (gauge_t value, const char* type) { - value_t values[1]; value_list_t vl = VALUE_LIST_INIT; - values[0].gauge = val; - - vl.values = values; - vl.values_len = STATIC_ARRAY_SIZE (values); + vl.values = &(value_t) { .gauge = value }; + vl.values_len = 1; sstrncpy (vl.host, config_host, sizeof (vl.host)); sstrncpy (vl.plugin, "tokyotyrant", sizeof (vl.plugin)); @@ -161,8 +104,8 @@ static void tt_submit (gauge_t val, const char* type) static void tt_open_db (void) { - char* host = NULL; - int port = DEFAULT_PORT; + const char *host; + int port = DEFAULT_PORT; if (rdb != NULL) return; @@ -171,7 +114,7 @@ static void tt_open_db (void) if (config_port != NULL) { - port = parse_service_name (config_port); + port = service_name_to_port_number (config_port); if (port <= 0) return; }