From: octo Date: Mon, 23 Jan 2006 10:39:27 +0000 (+0000) Subject: Fixes some bugs with the new battery module X-Git-Tag: collectd-3.7.0~38 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=275770d5b4a4b7649791a052fbfaa776b9487fe5;p=collectd.git Fixes some bugs with the new battery module --- diff --git a/configure.in b/configure.in index e7e2ea5a..21c09871 100644 --- a/configure.in +++ b/configure.in @@ -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) diff --git a/src/Makefile.am b/src/Makefile.am index b959eb8b..a98eab1b 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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 diff --git a/src/battery.c b/src/battery.c index a1c5e28b..b87b24ee 100644 --- a/src/battery.c +++ b/src/battery.c @@ -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