X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fmemcached.c;h=765a0fd3bcd501294abd2e23b02eb6a22365c34f;hb=fa82af13503a1195e1bfaef597ac33a3dc71a758;hp=77cadebb9a2962cc9a953372641325fd7fbe260c;hpb=f7649ae4a3270efe73f55bd00ca7fb89f269b8ec;p=collectd.git diff --git a/src/memcached.c b/src/memcached.c index 77cadebb..765a0fd3 100644 --- a/src/memcached.c +++ b/src/memcached.c @@ -44,9 +44,10 @@ struct memcached_s { char *name; - char *socket; char *host; - char *port; + char *socket; + char *connhost; + char *connport; }; typedef struct memcached_s memcached_t; @@ -59,9 +60,10 @@ static void memcached_free (void *arg) return; sfree (st->name); - sfree (st->socket); sfree (st->host); - sfree (st->port); + sfree (st->socket); + sfree (st->connhost); + sfree (st->connport); sfree (st); } @@ -98,29 +100,23 @@ static int memcached_connect_unix (memcached_t *st) static int memcached_connect_inet (memcached_t *st) { - const char *host; - const char *port; - struct addrinfo *ai_list; int status; int fd = -1; - host = (st->host != NULL) ? st->host : MEMCACHED_DEF_HOST; - port = (st->port != NULL) ? st->port : MEMCACHED_DEF_PORT; - struct addrinfo ai_hints = { .ai_family = AF_UNSPEC, .ai_flags = AI_ADDRCONFIG, .ai_socktype = SOCK_STREAM }; - status = getaddrinfo (host, port, &ai_hints, &ai_list); + status = getaddrinfo (st->connhost, st->connport, &ai_hints, &ai_list); if (status != 0) { char errbuf[1024]; ERROR ("memcached plugin: memcached_connect_inet: " "getaddrinfo(%s,%s) failed: %s", - host, port, + st->connhost, st->connport, (status == EAI_SYSTEM) ? sstrerror (errno, errbuf, sizeof (errbuf)) : gai_strerror (status)); @@ -239,23 +235,10 @@ static int memcached_query_daemon (char *buffer, size_t buffer_size, memcached_t static void memcached_init_vl (value_list_t *vl, memcached_t const *st) { - char const *host = st->host; - - /* Set vl->host to hostname_g, if: - * - Legacy mode is used. - * - "Socket" option is given (doc: "Host option is ignored"). - * - "Host" option is not provided. - * - "Host" option is set to "localhost" or "127.0.0.1". */ - if ((strcmp (st->name, "__legacy__") == 0) - || (st->socket != NULL) - || (st->host == NULL) - || (strcmp ("127.0.0.1", st->host) == 0) - || (strcmp ("localhost", st->host) == 0)) - host = hostname_g; - sstrncpy (vl->plugin, "memcached", sizeof (vl->plugin)); - sstrncpy (vl->host, host, sizeof (vl->host)); - if (strcmp (st->name, "__legacy__") != 0) + if (st->host != NULL) + sstrncpy (vl->host, st->host, sizeof (vl->host)); + if (st->name != NULL) sstrncpy (vl->plugin_instance, st->name, sizeof (vl->plugin_instance)); } @@ -545,8 +528,49 @@ static int memcached_add_read_callback (memcached_t *st) char callback_name[3*DATA_MAX_NAME_LEN]; int status; - assert (st->name != NULL); - ssnprintf (callback_name, sizeof (callback_name), "memcached/%s", st->name); + ssnprintf (callback_name, sizeof (callback_name), "memcached/%s", + (st->name != NULL) ? st->name : "__legacy__"); + + /* If no
used then: + * - Connect to the destination specified by