X-Git-Url: https://git.octo.it/?p=collectd.git;a=blobdiff_plain;f=src%2Fbattery.c;h=ce5818144138ce609ff70f1c48e9ac3c01889075;hp=272193ee507b742d78ac30de98cfe7466b697f45;hb=633c3966f770e4d46651a2fe219a18d8a9907a9f;hpb=b72d521340383b6418fa6a75faca3bc45f06b14a diff --git a/src/battery.c b/src/battery.c index 272193ee..ce581814 100644 --- a/src/battery.c +++ b/src/battery.c @@ -1,6 +1,7 @@ /** * collectd - src/battery.c * Copyright (C) 2006,2007 Florian octo Forster + * Copyright (C) 2008 Michał Mirosław * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the @@ -16,13 +17,16 @@ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * * Authors: - * Florian octo Forster + * Florian octo Forster + * Michał Mirosław **/ #include "collectd.h" #include "common.h" #include "plugin.h" +#include "utils_complain.h" + #if HAVE_MACH_MACH_TYPES_H # include #endif @@ -67,7 +71,7 @@ static const char *battery_acpi_dir = "/proc/acpi/battery"; static int battery_init (void) { #if HAVE_IOKIT_IOKITLIB_H || HAVE_IOKIT_PS_IOPOWERSOURCES_H - /* No init neccessary */ + /* No init necessary */ /* #endif HAVE_IOKIT_IOKITLIB_H || HAVE_IOKIT_PS_IOPOWERSOURCES_H */ #elif KERNEL_LINUX @@ -436,6 +440,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,8 +512,18 @@ 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, + /* include hidden */ 0); + 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 */