Fixes some bugs with the new battery module
authorocto <octo>
Mon, 23 Jan 2006 10:39:27 +0000 (10:39 +0000)
committerocto <octo>
Mon, 23 Jan 2006 10:39:27 +0000 (10:39 +0000)
configure.in
src/Makefile.am
src/battery.c

index e7e2ea5..21c0987 100644 (file)
@@ -1,5 +1,5 @@
 dnl Process this file with autoconf to produce a configure script.
-AC_INIT(collectd, 3.6.1)
+AC_INIT(collectd, 3.7.alpha0)
 AC_CONFIG_SRCDIR(src/collectd.c)
 AC_CONFIG_HEADERS(src/config.h)
 AM_INIT_AUTOMAKE(dist-bzip2)
index b959eb8..a98eab1 100644 (file)
@@ -32,7 +32,7 @@ pkglib_LTLIBRARIES =
 
 if BUILD_MODULE_BATTERY
 pkglib_LTLIBRARIES += battery.la
-battery_la_SOURCES = battery.c battery.h
+battery_la_SOURCES = battery.c
 battery_la_LDFLAGS = -module -avoid-version
 battery_la_CFLAGS  = -Wall -Werror
 collectd_LDADD += "-dlopen" battery.la
index a1c5e28..b87b24e 100644 (file)
@@ -84,19 +84,40 @@ static void battery_init (void)
 
 static void battery_current_write (char *host, char *inst, char *val)
 {
-       rrd_update_file (host, battery_current_file, val,
+       char filename[BUFSIZE];
+       int len;
+
+       len = snprintf (filename, BUFSIZE, battery_current_file, inst);
+       if ((len >= BUFSIZE) || (len < 0))
+               return;
+
+       rrd_update_file (host, filename, val,
                        ds_def_current, ds_num_current);
 }
 
 static void battery_voltage_write (char *host, char *inst, char *val)
 {
-       rrd_update_file (host, battery_voltage_file, val,
+       char filename[BUFSIZE];
+       int len;
+
+       len = snprintf (filename, BUFSIZE, battery_voltage_file, inst);
+       if ((len >= BUFSIZE) || (len < 0))
+               return;
+
+       rrd_update_file (host, filename, val,
                        ds_def_voltage, ds_num_voltage);
 }
 
 static void battery_charge_write (char *host, char *inst, char *val)
 {
-       rrd_update_file (host, battery_charge_file, val,
+       char filename[BUFSIZE];
+       int len;
+
+       len = snprintf (filename, BUFSIZE, battery_charge_file, inst);
+       if ((len >= BUFSIZE) || (len < 0))
+               return;
+
+       rrd_update_file (host, filename, val,
                        ds_def_charge, ds_num_charge);
 }
 
@@ -184,6 +205,20 @@ static void battery_read (void)
                fclose (fh);
                fh = NULL;
        }
+
+       if (access ("/proc/acpi/battery", R_OK | X_OK) == 0)
+       {
+               /*
+                * [11:00] <@tokkee> $ cat /proc/acpi/battery/BAT1/state
+                * [11:00] <@tokkee> present:                 yes
+                * [11:00] <@tokkee> capacity state:          ok
+                * [11:00] <@tokkee> charging state:          charging
+                * [11:00] <@tokkee> present rate:            1724 mA
+                * [11:00] <@tokkee> remaining capacity:      4136 mAh
+                * [11:00] <@tokkee> present voltage:         12428 mV
+                */
+               syslog (LOG_DEBUG, "Found directory `/proc/acpi/battery'");
+       }
 #endif /* KERNEL_LINUX */
 }
 #else