X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fmemcached.c;h=c3fa06b72b78401e38efb63b4f8c44440b9558f6;hb=3f2f61c7d74d9204405a4b0c21390451c98665a7;hp=a1825780ee1624ab7f4583bdf70295faef48a766;hpb=28b3758d4f394d6841571fe914f00c55504f66eb;p=collectd.git diff --git a/src/memcached.c b/src/memcached.c index a1825780..c3fa06b7 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); } } @@ -224,8 +236,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)); if (type_inst != NULL) { strncpy (vl.type_instance, type_inst, sizeof (vl.type_instance)); @@ -248,8 +260,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)); if (type_inst != NULL) { strncpy (vl.type_instance, type_inst, sizeof (vl.type_instance)); @@ -271,8 +283,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)); if (type_inst != NULL) { strncpy (vl.type_instance, type_inst, sizeof (vl.type_instance)); @@ -295,8 +307,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)); if (type_inst != NULL) { strncpy (vl.type_instance, type_inst, sizeof (vl.type_instance));