X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fpowerdns.c;h=164137ba39da5f9019bf037faff07efbafea1c26;hb=3602864950048219eb2981be13d902cc60117da2;hp=dee2c70fb3859e38bd1ba4db8e8c64c6d32e1418;hpb=e228afe28febdfd2af076f330e8766e82bc7e89a;p=collectd.git diff --git a/src/powerdns.c b/src/powerdns.c index dee2c70f..164137ba 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" @@ -264,7 +264,7 @@ static void submit (const char *plugin_instance, /* {{{ */ if (i >= lookup_table_length) { - DEBUG ("powerdns plugin: submit: Not found in lookup table: %s = %s;", + INFO ("powerdns plugin: submit: Not found in lookup table: %s = %s;", pdns_type, value); return; } @@ -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)) @@ -402,6 +401,7 @@ static int powerdns_get_data_dgram (list_item_t *item, /* {{{ */ FUNC_ERROR ("recv"); break; } + buffer_size = status + 1; status = 0; } while (0); @@ -411,7 +411,7 @@ static int powerdns_get_data_dgram (list_item_t *item, /* {{{ */ if (status != 0) return (-1); - buffer_size = status + 1; + assert (buffer_size > 0); buffer = (char *) malloc (buffer_size); if (buffer == NULL) { @@ -419,8 +419,8 @@ static int powerdns_get_data_dgram (list_item_t *item, /* {{{ */ return (-1); } - memcpy (buffer, temp, status); - buffer[status] = 0; + memcpy (buffer, temp, buffer_size - 1); + buffer[buffer_size - 1] = 0; *ret_buffer = buffer; *ret_buffer_size = buffer_size; @@ -618,7 +618,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 = */ " "); @@ -662,12 +662,18 @@ static int powerdns_read_recursor (list_item_t *item) /* {{{ */ ERROR ("powerdns plugin: powerdns_update_recursor_command failed."); return (-1); } + + DEBUG ("powerdns plugin: powerdns_read_recursor: item->command = %s;", + item->command); } assert (item->command != NULL); status = powerdns_get_data (item, &buffer, &buffer_size); if (status != 0) + { + ERROR ("powerdns plugin: powerdns_get_data failed."); return (-1); + } keys_list = strdup (item->command); if (keys_list == NULL) @@ -852,15 +858,9 @@ static int powerdns_config_add_server (oconfig_item_t *ci) /* {{{ */ break; } - if (item->command == NULL) - { - ERROR ("powerdns plugin: item->command == NULL."); - status = -1; - break; - } - 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)