X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fmemcached.c;h=7bdad0a01a475f42d7d5c9c37b07c1abf62a0144;hb=a94f5335f7b6a6e6672b84adb00f576b83d46b58;hp=ca93102f2a2865a9ab2b1bbb3919f7b1b064d272;hpb=4e6812d3e5073e5b4bd7eaef9f2539c8c9dd28a4;p=collectd.git diff --git a/src/memcached.c b/src/memcached.c index ca93102f..7bdad0a0 100644 --- a/src/memcached.c +++ b/src/memcached.c @@ -127,17 +127,29 @@ static int memcached_query_daemon (char *buffer, int buffer_size) /* {{{ */ { struct pollfd p; - int n; + int status; + memset (&p, 0, sizeof (p)); p.fd = fd; - p.events = POLLIN|POLLERR|POLLHUP; + p.events = POLLIN | POLLERR | POLLHUP; p.revents = 0; - n = poll(&p, 1, 3); - - if (n <= 0) { - ERROR ("memcached: poll() failed or timed out"); - return -1; + status = poll (&p, /* nfds = */ 1, /* timeout = */ 1000 * interval_g); + if (status <= 0) + { + if (status == 0) + { + ERROR ("memcached: poll(2) timed out after %i seconds.", interval_g); + } + else + { + char errbuf[1024]; + ERROR ("memcached: poll(2) failed: %s", + sstrerror (errno, errbuf, sizeof (errbuf))); + } + shutdown (fd, SHUT_RDWR); + close (fd); + return (-1); } } @@ -223,8 +235,8 @@ static void submit_counter (const char *type, const char *type_inst, vl.values = values; vl.values_len = 1; vl.time = time (NULL); - strcpy (vl.host, hostname_g); - strcpy (vl.plugin, "memcached"); + sstrncpy (vl.host, hostname_g, sizeof (vl.host)); + sstrncpy (vl.plugin, "memcached", sizeof (vl.plugin)); sstrncpy (vl.type, type, sizeof (vl.type)); if (type_inst != NULL) sstrncpy (vl.type_instance, type_inst, sizeof (vl.type_instance)); @@ -245,8 +257,8 @@ static void submit_counter2 (const char *type, const char *type_inst, vl.values = values; vl.values_len = 2; vl.time = time (NULL); - strcpy (vl.host, hostname_g); - strcpy (vl.plugin, "memcached"); + sstrncpy (vl.host, hostname_g, sizeof (vl.host)); + sstrncpy (vl.plugin, "memcached", sizeof (vl.plugin)); sstrncpy (vl.type, type, sizeof (vl.type)); if (type_inst != NULL) sstrncpy (vl.type_instance, type_inst, sizeof (vl.type_instance)); @@ -266,8 +278,8 @@ static void submit_gauge (const char *type, const char *type_inst, vl.values = values; vl.values_len = 1; vl.time = time (NULL); - strcpy (vl.host, hostname_g); - strcpy (vl.plugin, "memcached"); + sstrncpy (vl.host, hostname_g, sizeof (vl.host)); + sstrncpy (vl.plugin, "memcached", sizeof (vl.plugin)); sstrncpy (vl.type, type, sizeof (vl.type)); if (type_inst != NULL) sstrncpy (vl.type_instance, type_inst, sizeof (vl.type_instance)); @@ -288,8 +300,8 @@ static void submit_gauge2 (const char *type, const char *type_inst, vl.values = values; vl.values_len = 2; vl.time = time (NULL); - strcpy (vl.host, hostname_g); - strcpy (vl.plugin, "memcached"); + sstrncpy (vl.host, hostname_g, sizeof (vl.host)); + sstrncpy (vl.plugin, "memcached", sizeof (vl.plugin)); sstrncpy (vl.type, type, sizeof (vl.type)); if (type_inst != NULL) sstrncpy (vl.type_instance, type_inst, sizeof (vl.type_instance));