Code

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 e7e2ea5aee5624ad6d9f3f9f6d4565ff3d095aa0..21c09871c833a73a2d21f7cee7d3bd727ead3714 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 b959eb8b29fc3b389d8d9f2b4f53dc347ebfbd86..a98eab1bce0a90d11f01941bf37919581fe99bbe 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 a1c5e28b3be81a7e49d80b8e94a548f30963d495..b87b24ee39b6209c41fc0da16521ce17c5280ce7 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