X-Git-Url: https://git.octo.it/?p=collectd.git;a=blobdiff_plain;f=src%2Fpowerdns.c;h=eb3ec537c35019124fe1db7833df138936a4a513;hp=da72ec8d73d7584e7e4d44829a5724c47a90de97;hb=d486225f89ea52d8ed2b4242eba2ad94c409f837;hpb=eeca9dc658dfa9ed3c8bfea609fa0a82f9326874 diff --git a/src/powerdns.c b/src/powerdns.c index da72ec8d..eb3ec537 100644 --- a/src/powerdns.c +++ b/src/powerdns.c @@ -44,15 +44,12 @@ #endif #define FUNC_ERROR(func) \ do { \ - char errbuf[1024]; \ - ERROR("powerdns plugin: %s failed: %s", func, \ - sstrerror(errno, errbuf, sizeof(errbuf))); \ + ERROR("powerdns plugin: %s failed: %s", func, STRERRNO); \ } while (0) #define SOCK_ERROR(func, sockpath) \ do { \ - char errbuf[1024]; \ ERROR("powerdns plugin: Socket `%s` %s failed: %s", sockpath, func, \ - sstrerror(errno, errbuf, sizeof(errbuf))); \ + STRERRNO); \ } while (0) #define SERVER_SOCKET LOCALSTATEDIR "/run/pdns.controlsocket" @@ -307,10 +304,10 @@ static statname_lookup_t lookup_table[] = /* {{{ */ {"uptime", "uptime", NULL}}; /* }}} */ static int lookup_table_length = STATIC_ARRAY_SIZE(lookup_table); -static llist_t *list = NULL; +static llist_t *list; #define PDNS_LOCAL_SOCKPATH LOCALSTATEDIR "/run/" PACKAGE_NAME "-powerdns" -static char *local_sockpath = NULL; +static char *local_sockpath; /* TODO: Do this before 4.4: * - Update the collectd.conf(5) manpage. @@ -355,7 +352,7 @@ static void submit(const char *plugin_instance, /* {{{ */ } if (ds->ds_num != 1) { - ERROR("powerdns plugin: type `%s' has %zu data sources, " + ERROR("powerdns plugin: type `%s' has %" PRIsz " data sources, " "but I can only handle one.", type, ds->ds_num); return; @@ -395,7 +392,7 @@ static int powerdns_get_data_dgram(list_item_t *item, char **ret_buffer) { sd = socket(PF_UNIX, item->socktype, 0); if (sd < 0) { FUNC_ERROR("socket"); - return (-1); + return -1; } sa_unix.sun_family = AF_UNIX; @@ -407,7 +404,7 @@ static int powerdns_get_data_dgram(list_item_t *item, char **ret_buffer) { if ((status != 0) && (errno != ENOENT)) { SOCK_ERROR("unlink", sa_unix.sun_path); close(sd); - return (-1); + return -1; } do /* while (0) */ @@ -465,20 +462,20 @@ static int powerdns_get_data_dgram(list_item_t *item, char **ret_buffer) { unlink(sa_unix.sun_path); if (status != 0) - return (-1); + return -1; assert(buffer_size > 0); buffer = malloc(buffer_size); if (buffer == NULL) { FUNC_ERROR("malloc"); - return (-1); + return -1; } memcpy(buffer, temp, buffer_size - 1); buffer[buffer_size - 1] = 0; *ret_buffer = buffer; - return (0); + return 0; } /* }}} int powerdns_get_data_dgram */ static int powerdns_get_data_stream(list_item_t *item, char **ret_buffer) { @@ -493,7 +490,7 @@ static int powerdns_get_data_stream(list_item_t *item, char **ret_buffer) { sd = socket(PF_UNIX, item->socktype, 0); if (sd < 0) { FUNC_ERROR("socket"); - return (-1); + return -1; } struct timeval timeout; @@ -503,7 +500,7 @@ static int powerdns_get_data_stream(list_item_t *item, char **ret_buffer) { if (status != 0) { FUNC_ERROR("setsockopt"); close(sd); - return (-1); + return -1; } status = @@ -511,7 +508,7 @@ static int powerdns_get_data_stream(list_item_t *item, char **ret_buffer) { if (status != 0) { SOCK_ERROR("connect", item->sockaddr.sun_path); close(sd); - return (-1); + return -1; } /* strlen + 1, because we need to send the terminating NULL byte, too. */ @@ -520,7 +517,7 @@ static int powerdns_get_data_stream(list_item_t *item, char **ret_buffer) { if (status < 0) { SOCK_ERROR("send", item->sockaddr.sun_path); close(sd); - return (-1); + return -1; } while (42) { @@ -559,12 +556,12 @@ static int powerdns_get_data_stream(list_item_t *item, char **ret_buffer) { static int powerdns_get_data(list_item_t *item, char **ret_buffer) { if (item->socktype == SOCK_DGRAM) - return (powerdns_get_data_dgram(item, ret_buffer)); + return powerdns_get_data_dgram(item, ret_buffer); else if (item->socktype == SOCK_STREAM) - return (powerdns_get_data_stream(item, ret_buffer)); + return powerdns_get_data_stream(item, ret_buffer); else { ERROR("powerdns plugin: Unknown socket type: %i", (int)item->socktype); - return (-1); + return -1; } } /* int powerdns_get_data */ @@ -574,14 +571,14 @@ static int powerdns_read_server(list_item_t *item) /* {{{ */ item->command = strdup(SERVER_COMMAND); if (item->command == NULL) { ERROR("powerdns plugin: strdup failed."); - return (-1); + return -1; } char *buffer = NULL; int status = powerdns_get_data(item, &buffer); if (status != 0) { ERROR("powerdns plugin: powerdns_get_data failed."); - return (status); + return status; } if (buffer == NULL) { return EINVAL; @@ -628,7 +625,7 @@ static int powerdns_read_server(list_item_t *item) /* {{{ */ sfree(buffer); - return (0); + return 0; } /* }}} int powerdns_read_server */ /* @@ -644,7 +641,7 @@ static int powerdns_update_recursor_command(list_item_t *li) /* {{{ */ int status; if (li == NULL) - return (0); + return 0; if (li->fields_num < 1) { sstrncpy(buffer, RECURSOR_COMMAND, sizeof(buffer)); @@ -655,7 +652,7 @@ static int powerdns_update_recursor_command(list_item_t *li) /* {{{ */ /* seperator = */ " "); if (status < 0) { ERROR("powerdns plugin: strjoin failed."); - return (-1); + return -1; } buffer[sizeof(buffer) - 1] = 0; size_t len = strlen(buffer); @@ -670,10 +667,10 @@ static int powerdns_update_recursor_command(list_item_t *li) /* {{{ */ li->command = strdup(buffer); if (li->command == NULL) { ERROR("powerdns plugin: strdup failed."); - return (-1); + return -1; } - return (0); + return 0; } /* }}} int powerdns_update_recursor_command */ static int powerdns_read_recursor(list_item_t *item) /* {{{ */ @@ -693,7 +690,7 @@ static int powerdns_read_recursor(list_item_t *item) /* {{{ */ status = powerdns_update_recursor_command(item); if (status != 0) { ERROR("powerdns plugin: powerdns_update_recursor_command failed."); - return (-1); + return -1; } DEBUG("powerdns plugin: powerdns_read_recursor: item->command = %s;", @@ -704,14 +701,14 @@ static int powerdns_read_recursor(list_item_t *item) /* {{{ */ status = powerdns_get_data(item, &buffer); if (status != 0) { ERROR("powerdns plugin: powerdns_get_data failed."); - return (-1); + return -1; } keys_list = strdup(item->command); if (keys_list == NULL) { FUNC_ERROR("strdup"); sfree(buffer); - return (-1); + return -1; } key_saveptr = NULL; @@ -734,7 +731,7 @@ static int powerdns_read_recursor(list_item_t *item) /* {{{ */ sfree(buffer); sfree(keys_list); - return (0); + return 0; } /* }}} int powerdns_read_recursor */ static int powerdns_config_add_collect(list_item_t *li, /* {{{ */ @@ -744,21 +741,21 @@ static int powerdns_config_add_collect(list_item_t *li, /* {{{ */ if (ci->values_num < 1) { WARNING("powerdns plugin: The `Collect' option needs " "at least one argument."); - return (-1); + return -1; } for (int i = 0; i < ci->values_num; i++) if (ci->values[i].type != OCONFIG_TYPE_STRING) { WARNING("powerdns plugin: Only string arguments are allowed to " "the `Collect' option."); - return (-1); + return -1; } temp = realloc(li->fields, sizeof(char *) * (li->fields_num + ci->values_num)); if (temp == NULL) { WARNING("powerdns plugin: realloc failed."); - return (-1); + return -1; } li->fields = temp; @@ -774,7 +771,7 @@ static int powerdns_config_add_collect(list_item_t *li, /* {{{ */ /* Invalidate a previously computed command */ sfree(li->command); - return (0); + return 0; } /* }}} int powerdns_config_add_collect */ static int powerdns_config_add_server(oconfig_item_t *ci) /* {{{ */ @@ -787,20 +784,20 @@ static int powerdns_config_add_server(oconfig_item_t *ci) /* {{{ */ if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) { WARNING("powerdns plugin: `%s' needs exactly one string argument.", ci->key); - return (-1); + return -1; } item = calloc(1, sizeof(*item)); if (item == NULL) { ERROR("powerdns plugin: calloc failed."); - return (-1); + return -1; } item->instance = strdup(ci->values[0].value.string); if (item->instance == NULL) { ERROR("powerdns plugin: strdup failed."); sfree(item); - return (-1); + return -1; } /* @@ -819,7 +816,7 @@ static int powerdns_config_add_server(oconfig_item_t *ci) /* {{{ */ } else { /* We must never get here.. */ assert(0); - return (-1); + return -1; } status = 0; @@ -866,13 +863,13 @@ static int powerdns_config_add_server(oconfig_item_t *ci) /* {{{ */ if (status != 0) { sfree(socket_temp); sfree(item); - return (-1); + return -1; } DEBUG("powerdns plugin: Add server: instance = %s;", item->instance); sfree(socket_temp); - return (0); + return 0; } /* }}} int powerdns_config_add_server */ static int powerdns_config(oconfig_item_t *ci) /* {{{ */ @@ -884,7 +881,7 @@ static int powerdns_config(oconfig_item_t *ci) /* {{{ */ if (list == NULL) { ERROR("powerdns plugin: `llist_create' failed."); - return (-1); + return -1; } } @@ -902,7 +899,7 @@ static int powerdns_config(oconfig_item_t *ci) /* {{{ */ } else { char *temp = strdup(option->values[0].value.string); if (temp == NULL) - return (1); + return 1; sfree(local_sockpath); local_sockpath = temp; } @@ -911,7 +908,7 @@ static int powerdns_config(oconfig_item_t *ci) /* {{{ */ } } /* for (i = 0; i < ci->children_num; i++) */ - return (0); + return 0; } /* }}} int powerdns_config */ static int powerdns_read(void) { @@ -920,12 +917,12 @@ static int powerdns_read(void) { item->func(item); } - return (0); + return 0; } /* static int powerdns_read */ static int powerdns_shutdown(void) { if (list == NULL) - return (0); + return 0; for (llentry_t *e = llist_head(list); e != NULL; e = e->next) { list_item_t *item = (list_item_t *)e->value; @@ -939,7 +936,7 @@ static int powerdns_shutdown(void) { llist_destroy(list); list = NULL; - return (0); + return 0; } /* static int powerdns_shutdown */ void module_register(void) { @@ -947,5 +944,3 @@ void module_register(void) { plugin_register_read("powerdns", powerdns_read); plugin_register_shutdown("powerdns", powerdns_shutdown); } /* void module_register */ - -/* vim: set sw=2 sts=2 ts=8 fdm=marker : */