From: Sebastian Harl Date: Tue, 10 Mar 2009 21:06:10 +0000 (+0100) Subject: battery plugin: Don't complain about missing /proc/acpi/battery each interval. X-Git-Tag: collectd-4.5.4~22 X-Git-Url: https://git.octo.it/?a=commitdiff_plain;h=0c0db283184765cb40fcd8cd52735b6e2cc7db31;p=collectd.git battery plugin: Don't complain about missing /proc/acpi/battery each interval. Instead, complain once when the read callback is called for the first time. --- diff --git a/src/battery.c b/src/battery.c index 416f3397..3e726991 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 @@ -437,6 +439,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]; @@ -507,8 +511,17 @@ static int battery_read (void) battery_submit ("0", "voltage", voltage); } - walk_directory (battery_acpi_dir, battery_read_acpi, - /* user_data = */ NULL); + 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 */