From: Florian Forster Date: Thu, 22 Dec 2016 09:57:57 +0000 (+0100) Subject: Merge branch 'collectd-5.7' X-Git-Tag: collectd-5.8.0~261 X-Git-Url: https://git.octo.it/?p=collectd.git;a=commitdiff_plain;h=786a6be461cf58ef2b8c57974cad2a79ba2ee82c;hp=7269bf71e30f0a70a9eb954f6b0a6fe1b10eb6e5 Merge branch 'collectd-5.7' --- diff --git a/src/battery.c b/src/battery.c index 5c02fee2..78e96b25 100644 --- a/src/battery.c +++ b/src/battery.c @@ -350,10 +350,12 @@ static int sysfs_file_to_buffer(char const *dir, /* {{{ */ ssnprintf(filename, sizeof(filename), "%s/%s/%s", dir, power_supply, basename); - status = (int)read_file_contents(filename, buffer, buffer_size); + status = (int)read_file_contents(filename, buffer, buffer_size - 1); if (status < 0) return status; + buffer[status] = '\0'; + strstripnewline(buffer); return 0; } /* }}} int sysfs_file_to_buffer */ @@ -364,7 +366,7 @@ static int sysfs_file_to_gauge(char const *dir, /* {{{ */ char const *power_supply, char const *basename, gauge_t *ret_value) { int status; - char buffer[32] = ""; + char buffer[32]; status = sysfs_file_to_buffer(dir, power_supply, basename, buffer, sizeof(buffer)); diff --git a/src/daemon/common.c b/src/daemon/common.c index 40822d0c..64dbee6f 100644 --- a/src/daemon/common.c +++ b/src/daemon/common.c @@ -267,8 +267,10 @@ ssize_t swrite(int fd, const void *buf, size_t count) { ptr = (const char *)buf; nleft = count; - if (fd < 0) - return (-1); + if (fd < 0) { + errno = EINVAL; + return errno; + } /* checking for closed peer connection */ pfd.fd = fd; @@ -277,10 +279,9 @@ ssize_t swrite(int fd, const void *buf, size_t count) { if (poll(&pfd, 1, 0) > 0) { char buffer[32]; if (recv(fd, buffer, sizeof(buffer), MSG_PEEK | MSG_DONTWAIT) == 0) { - // if recv returns zero (even though poll() said there is data to be - // read), - // that means the connection has been closed - return -1; + /* if recv returns zero (even though poll() said there is data to be + * read), that means the connection has been closed */ + return errno ? errno : -1; } } @@ -291,7 +292,7 @@ ssize_t swrite(int fd, const void *buf, size_t count) { continue; if (status < 0) - return (status); + return errno ? errno : status; nleft = nleft - ((size_t)status); ptr = ptr + ((size_t)status); diff --git a/src/daemon/configfile.c b/src/daemon/configfile.c index b57aadc8..654cc49b 100644 --- a/src/daemon/configfile.c +++ b/src/daemon/configfile.c @@ -1119,14 +1119,36 @@ int cf_util_get_boolean(const oconfig_item_t *ci, _Bool *ret_bool) /* {{{ */ if ((ci == NULL) || (ret_bool == NULL)) return (EINVAL); - if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN)) { + if ((ci->values_num != 1) || ((ci->values[0].type != OCONFIG_TYPE_BOOLEAN) && + (ci->values[0].type != OCONFIG_TYPE_STRING))) { ERROR("cf_util_get_boolean: The %s option requires " "exactly one boolean argument.", ci->key); return (-1); } - *ret_bool = ci->values[0].value.boolean ? 1 : 0; + switch (ci->values[0].type) { + case OCONFIG_TYPE_BOOLEAN: + *ret_bool = ci->values[0].value.boolean ? 1 : 0; + break; + case OCONFIG_TYPE_STRING: + WARNING("cf_util_get_boolean: Using string value `%s' for boolean option " + "`%s' is deprecated and will be removed in future releases. " + "Use unquoted true or false instead.", + ci->values[0].value.string, ci->key); + + if (IS_TRUE(ci->values[0].value.string)) + *ret_bool = 1; + else if (IS_FALSE(ci->values[0].value.string)) + *ret_bool = 0; + else { + ERROR("cf_util_get_boolean: Cannot parse string value `%s' of the `%s' " + "option as a boolean value.", + ci->values[0].value.string, ci->key); + return (-1); + } + break; + } return (0); } /* }}} int cf_util_get_boolean */ diff --git a/src/dpdkstat.c b/src/dpdkstat.c index de75c0c0..2686be15 100644 --- a/src/dpdkstat.c +++ b/src/dpdkstat.c @@ -159,8 +159,8 @@ static int dpdk_shm_init(size_t size); static void dpdk_config_init_default(void) { g_configuration->interval = plugin_get_interval(); if (g_configuration->interval == cf_get_default_interval()) - WARNING("dpdkstat: No time interval was configured, default value %lu ms " - "is set", + WARNING("dpdkstat: No time interval was configured, default value %" PRIu64 + " ms is set", CDTIME_T_TO_MS(g_configuration->interval)); /* Default is all ports enabled */ g_configuration->enabled_port_mask = ~0; @@ -289,13 +289,13 @@ static int dpdk_shm_init(size_t size) { if (err) { ERROR("dpdkstat semaphore init failed: %s", sstrerror(errno, errbuf, sizeof(errbuf))); - goto fail_close; + goto close; } err = sem_init(&g_configuration->sema_stats_in_shm, 1, 0); if (err) { ERROR("dpdkstat semaphore init failed: %s", sstrerror(errno, errbuf, sizeof(errbuf))); - goto fail_close; + goto close; } g_configuration->xstats = NULL; @@ -413,7 +413,7 @@ static int dpdk_helper_spawn(enum DPDK_HELPER_ACTION action) { if (pid > 0) { close(g_configuration->helper_pipes[1]); g_configuration->helper_pid = pid; - DEBUG("dpdkstat: helper pid %lu", (long)g_configuration->helper_pid); + DEBUG("dpdkstat: helper pid %li", (long)g_configuration->helper_pid); /* Kick helper once its alive to have it start processing */ sem_post(&g_configuration->sema_helper_get_stats); } else if (pid == 0) { diff --git a/src/netapp.c b/src/netapp.c index 5b0827c9..13e1db92 100644 --- a/src/netapp.c +++ b/src/netapp.c @@ -674,7 +674,7 @@ static int submit_double(const char *host, const char *plugin_inst, /* {{{ */ const char *type, const char *type_inst, double d, cdtime_t timestamp, cdtime_t interval) { return (submit_values(host, plugin_inst, type, type_inst, - &(value_t){.gauge = counter}, 1, timestamp, interval)); + &(value_t){.gauge = d}, 1, timestamp, interval)); } /* }}} int submit_uint64 */ /* Calculate hit ratio from old and new counters and submit the resulting @@ -1910,15 +1910,13 @@ static int cna_query_quota(host_config_t *host) /* {{{ */ static int cna_handle_snapvault_data(const char *hostname, /* {{{ */ cfg_snapvault_t *cfg_snapvault, na_elem_t *data, cdtime_t interval) { - na_elem_iter_t status_iter; - - status = na_elem_child(data, "status-list"); - if (!status) { + na_elem_t *status_list = na_elem_child(data, "status-list"); + if (status_list == NULL) { ERROR("netapp plugin: SnapVault status record missing status-list"); return (0); } - status_iter = na_child_iterator(status); + na_elem_iter_t status_iter = na_child_iterator(status_list); for (na_elem_t *status = na_iterator_next(&status_iter); status != NULL; status = na_iterator_next(&status_iter)) { const char *dest_sys, *dest_path, *src_sys, *src_path;