summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: cd2238b)
raw | patch | inline | side by side (parent: cd2238b)
author | Florian Forster <octo@collectd.org> | |
Thu, 4 Aug 2016 09:30:18 +0000 (11:30 +0200) | ||
committer | Florian Forster <octo@collectd.org> | |
Thu, 4 Aug 2016 09:56:03 +0000 (11:56 +0200) |
Previously, the code would use the value of the "Host" option or
"127.0.0.1" if that option was unset (plus special cases for UNIX
sockets and a legacy mode). Obviously, "127.0.0.1" is a bad default.
This patch emulates the behavior of the MySQL plugin: if the "Host"
option is unset or set to either "localhost" or "127.0.0.1", the global
hostname_g variable is used.
Fixes: #801
Supersedes: #894
"127.0.0.1" if that option was unset (plus special cases for UNIX
sockets and a legacy mode). Obviously, "127.0.0.1" is a bad default.
This patch emulates the behavior of the MySQL plugin: if the "Host"
option is unset or set to either "localhost" or "127.0.0.1", the global
hostname_g variable is used.
Fixes: #801
Supersedes: #894
src/memcached.c | patch | blob | history |
diff --git a/src/memcached.c b/src/memcached.c
index e398dd9eb02ef6bd9b85757ff436f70a01c715b4..02f4203ae5b6b39a707627a1b6b61ddde8e25b51 100644 (file)
--- a/src/memcached.c
+++ b/src/memcached.c
@@ -240,21 +240,24 @@ 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));
- if (strcmp (st->name, "__legacy__") == 0) /* legacy mode */
- {
- sstrncpy (vl->host, hostname_g, sizeof (vl->host));
- }
- else
- {
- if (st->socket != NULL)
- sstrncpy (vl->host, hostname_g, sizeof (vl->host));
- else
- sstrncpy (vl->host,
- (st->host != NULL) ? st->host : MEMCACHED_DEF_HOST,
- sizeof (vl->host));
+ sstrncpy (vl->host, host, sizeof (vl->host));
+ if (strcmp (st->name, "__legacy__") != 0)
sstrncpy (vl->plugin_instance, st->name, sizeof (vl->plugin_instance));
- }
}
static void submit_derive (const char *type, const char *type_inst,