X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fpowerdns.c;h=7288c37239b4f55a9477ae7d8c07be4d57accfa9;hb=23cbc33ec79a98119b284c2db6f5a228a97cac3b;hp=51e39ee245e87b2deb4d9e51e706df1147c26a3e;hpb=b88f9d8a83ff838523a21e4b191f447888d651cd;p=collectd.git diff --git a/src/powerdns.c b/src/powerdns.c index 51e39ee2..7288c372 100644 --- a/src/powerdns.c +++ b/src/powerdns.c @@ -45,10 +45,10 @@ #endif #define FUNC_ERROR(func) do { char errbuf[1024]; ERROR ("powerdns plugin: %s failed: %s", func, sstrerror (errno, errbuf, sizeof (errbuf))); } while (0) -#define SERVER_SOCKET "/var/run/pdns.controlsocket" +#define SERVER_SOCKET LOCALSTATEDIR"/run/pdns.controlsocket" #define SERVER_COMMAND "SHOW *" -#define RECURSOR_SOCKET "/var/run/pdns_recursor.controlsocket" +#define RECURSOR_SOCKET LOCALSTATEDIR"/run/pdns_recursor.controlsocket" #define RECURSOR_COMMAND "get noerror-answers nxdomain-answers " \ "servfail-answers sys-msec user-msec qa-latency cache-entries cache-hits " \ "cache-misses questions" @@ -317,14 +317,14 @@ static void submit (const char *plugin_instance, /* {{{ */ vl.values = values; vl.values_len = 1; - vl.time = time (NULL); sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, "powerdns", sizeof (vl.plugin)); + sstrncpy (vl.type, type, sizeof (vl.type)); if (type_instance != NULL) sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance)); - plugin_dispatch_values (type, &vl); + plugin_dispatch_values (&vl); } /* }}} static void submit */ static int powerdns_get_data_dgram (list_item_t *item, /* {{{ */ @@ -349,10 +349,9 @@ static int powerdns_get_data_dgram (list_item_t *item, /* {{{ */ memset (&sa_unix, 0, sizeof (sa_unix)); sa_unix.sun_family = AF_UNIX; - strncpy (sa_unix.sun_path, + sstrncpy (sa_unix.sun_path, (local_sockpath != NULL) ? local_sockpath : PDNS_LOCAL_SOCKPATH, sizeof (sa_unix.sun_path)); - sa_unix.sun_path[sizeof (sa_unix.sun_path) - 1] = 0; status = unlink (sa_unix.sun_path); if ((status != 0) && (errno != ENOENT)) @@ -381,6 +380,18 @@ static int powerdns_get_data_dgram (list_item_t *item, /* {{{ */ break; } + struct timeval timeout; + timeout.tv_sec=2; + if (timeout.tv_sec < interval_g * 3 / 4) + timeout.tv_sec = interval_g * 3 / 4; + timeout.tv_usec=0; + status = setsockopt (sd, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof (timeout)); + if (status != 0) + { + FUNC_ERROR ("setsockopt"); + break; + } + status = connect (sd, (struct sockaddr *) &item->sockaddr, sizeof (item->sockaddr)); if (status != 0) @@ -619,7 +630,7 @@ static int powerdns_update_recursor_command (list_item_t *li) /* {{{ */ } else { - strcpy (buffer, "get "); + sstrncpy (buffer, "get ", sizeof (buffer)); status = strjoin (&buffer[4], sizeof (buffer) - strlen ("get "), li->fields, li->fields_num, /* seperator = */ " "); @@ -860,7 +871,8 @@ static int powerdns_config_add_server (oconfig_item_t *ci) /* {{{ */ } item->sockaddr.sun_family = AF_UNIX; - sstrncpy (item->sockaddr.sun_path, socket_temp, UNIX_PATH_MAX); + sstrncpy (item->sockaddr.sun_path, socket_temp, + sizeof (item->sockaddr.sun_path)); e = llentry_create (item->instance, item); if (e == NULL) @@ -911,11 +923,18 @@ static int powerdns_config (oconfig_item_t *ci) /* {{{ */ powerdns_config_add_server (option); else if (strcasecmp ("LocalSocket", option->key) == 0) { - char *temp = strdup (option->key); - if (temp == NULL) - return (1); - sfree (local_sockpath); - local_sockpath = temp; + if ((option->values_num != 1) || (option->values[0].type != OCONFIG_TYPE_STRING)) + { + WARNING ("powerdns plugin: `%s' needs exactly one string argument.", option->key); + } + else + { + char *temp = strdup (option->values[0].value.string); + if (temp == NULL) + return (1); + sfree (local_sockpath); + local_sockpath = temp; + } } else {