#include "common.h"
#include "plugin.h"
-#include "configfile.h"
#include <netdb.h>
#include <sys/un.h>
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,
static int memcached_add_read_callback (memcached_t *st)
{
- user_data_t ud = { 0 };
char callback_name[3*DATA_MAX_NAME_LEN];
int status;
- ud.data = st;
- ud.free_func = memcached_free;
-
assert (st->name != NULL);
ssnprintf (callback_name, sizeof (callback_name), "memcached/%s", st->name);
+ user_data_t ud = {
+ .data = st,
+ .free_func = memcached_free
+ };
+
status = plugin_register_complex_read (/* group = */ "memcached",
/* name = */ callback_name,
/* callback = */ memcached_read,