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 */
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));
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;
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;
}
}
continue;
if (status < 0)
- return (status);
+ return errno ? errno : status;
nleft = nleft - ((size_t)status);
ptr = ptr + ((size_t)status);
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 */
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;
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;
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) {
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
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;