X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fbattery.c;h=33ba29231556bc7feec6a00b35276931224100d1;hb=9b626288aff81c68fe19210a58b4a32eeefde9d3;hp=74b3344a1e28e494861d45d3732d335c1b82fcf4;hpb=17019425b82a8f0c925b90a7638678b1b3b71a25;p=collectd.git diff --git a/src/battery.c b/src/battery.c index 74b3344a..33ba2923 100644 --- a/src/battery.c +++ b/src/battery.c @@ -23,6 +23,8 @@ #include "common.h" #include "plugin.h" +#include "utils_complain.h" + #if HAVE_MACH_MACH_TYPES_H # include #endif @@ -98,9 +100,8 @@ static void battery_submit (const char *plugin_instance, const char *type, doubl vl.values = values; vl.values_len = 1; - vl.time = time (NULL); - strcpy (vl.host, hostname_g); - strcpy (vl.plugin, "battery"); + sstrncpy (vl.host, hostname_g, sizeof (vl.host)); + sstrncpy (vl.plugin, "battery", sizeof (vl.plugin)); sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance)); sstrncpy (vl.type, type, sizeof (vl.type)); @@ -315,7 +316,8 @@ static void get_via_generic_iokit (double *ret_charge, #endif /* HAVE_IOKIT_IOKITLIB_H */ #if KERNEL_LINUX -static int battery_read_acpi (const char *name) +static int battery_read_acpi (const char __attribute__((unused)) *dir, + const char *name, void __attribute__((unused)) *user_data) { double current = INVALID_VALUE; double voltage = INVALID_VALUE; @@ -436,6 +438,8 @@ static int battery_read (void) /* #endif HAVE_IOKIT_IOKITLIB_H || HAVE_IOKIT_PS_IOPOWERSOURCES_H */ #elif KERNEL_LINUX + static c_complain_t acpi_dir_complaint = C_COMPLAIN_INIT_STATIC; + FILE *fh; char buffer[1024]; char filename[256]; @@ -506,7 +510,17 @@ static int battery_read (void) battery_submit ("0", "voltage", voltage); } - walk_directory (battery_acpi_dir, battery_read_acpi); + if (0 == access (battery_acpi_dir, R_OK)) + walk_directory (battery_acpi_dir, battery_read_acpi, + /* user_data = */ NULL); + else + { + char errbuf[1024]; + c_complain_once (LOG_WARNING, &acpi_dir_complaint, + "battery plugin: Failed to access `%s': %s", + battery_acpi_dir, + sstrerror (errno, errbuf, sizeof (errbuf))); + } #endif /* KERNEL_LINUX */