projects
/
collectd.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
src/Makefile: Don't set subdir-objects.
[collectd.git]
/
src
/
battery.c
diff --git
a/src/battery.c
b/src/battery.c
index
62c2964
..
8a96e89
100644
(file)
--- a/
src/battery.c
+++ b/
src/battery.c
@@
-143,7
+143,7
@@
static void submit_capacity (char const *plugin_instance, /* {{{ */
} /* }}} void submit_capacity */
#if HAVE_IOKIT_PS_IOPOWERSOURCES_H || HAVE_IOKIT_IOKITLIB_H
} /* }}} void submit_capacity */
#if HAVE_IOKIT_PS_IOPOWERSOURCES_H || HAVE_IOKIT_IOKITLIB_H
-static double dict_get_double (CFDictionaryRef dict, char *key_string) /* {{{ */
+static double dict_get_double (CFDictionaryRef dict, c
onst c
har *key_string) /* {{{ */
{
double val_double;
long long val_int;
{
double val_double;
long long val_int;
@@
-341,7
+341,7
@@
static void get_via_generic_iokit (double *ret_capacity_full, /* {{{ */
*ret_voltage = temp_double / 1000.0;
}
}
*ret_voltage = temp_double / 1000.0;
}
}
-
+
CFRelease (bat_root_dict);
}
CFRelease (bat_root_dict);
}
@@
-358,7
+358,7
@@
static int battery_read (void) /* {{{ */
* IOPowerSources. IOKit, on the other hand, only reports the full
* capacity. We use the two to calculate the current charged capacity. */
gauge_t charge_rel = NAN; /* Current charge in percent */
* IOPowerSources. IOKit, on the other hand, only reports the full
* capacity. We use the two to calculate the current charged capacity. */
gauge_t charge_rel = NAN; /* Current charge in percent */
- gauge_t capacity_charged
= NAN
; /* Charged capacity */
+ gauge_t capacity_charged; /* Charged capacity */
gauge_t capacity_full = NAN; /* Total capacity */
gauge_t capacity_design = NAN; /* Full design capacity */
gauge_t capacity_full = NAN; /* Total capacity */
gauge_t capacity_design = NAN; /* Full design capacity */
@@
-376,6
+376,8
@@
static int battery_read (void) /* {{{ */
battery_submit ("0", "current", current);
if (!isnan (voltage))
battery_submit ("0", "voltage", voltage);
battery_submit ("0", "current", current);
if (!isnan (voltage))
battery_submit ("0", "voltage", voltage);
+
+ return (0);
} /* }}} int battery_read */
/* #endif HAVE_IOKIT_IOKITLIB_H || HAVE_IOKIT_PS_IOPOWERSOURCES_H */
} /* }}} int battery_read */
/* #endif HAVE_IOKIT_IOKITLIB_H || HAVE_IOKIT_PS_IOPOWERSOURCES_H */
@@
-414,10
+416,13
@@
static int sysfs_file_to_buffer(char const *dir, /* {{{ */
if (fgets (buffer, buffer_size, fp) == NULL)
{
if (fgets (buffer, buffer_size, fp) == NULL)
{
- char errbuf[1024];
status = errno;
status = errno;
- WARNING ("battery plugin: fgets failed: %s",
- sstrerror (status, errbuf, sizeof (errbuf)));
+ if (status != ENODEV)
+ {
+ char errbuf[1024];
+ WARNING ("battery plugin: fgets (%s) failed: %s", filename,
+ sstrerror (status, errbuf, sizeof (errbuf)));
+ }
fclose (fp);
return status;
}
fclose (fp);
return status;
}
@@
-511,13
+516,15
@@
static int read_sysfs_callback (char const *dir, /* {{{ */
v *= -1.0;
battery_submit (plugin_instance, "power", v * SYSFS_FACTOR);
}
v *= -1.0;
battery_submit (plugin_instance, "power", v * SYSFS_FACTOR);
}
+ if (sysfs_file_to_gauge (dir, power_supply, "current_now", &v) == 0)
+ {
+ if (discharging)
+ v *= -1.0;
+ battery_submit (plugin_instance, "current", v * SYSFS_FACTOR);
+ }
if (sysfs_file_to_gauge (dir, power_supply, "voltage_now", &v) == 0)
battery_submit (plugin_instance, "voltage", v * SYSFS_FACTOR);
if (sysfs_file_to_gauge (dir, power_supply, "voltage_now", &v) == 0)
battery_submit (plugin_instance, "voltage", v * SYSFS_FACTOR);
-#if 0
- if (sysfs_file_to_gauge (dir, power_supply, "voltage_min_design", &v) == 0)
- battery_submit (plugin_instance, "voltage", v * SYSFS_FACTOR);
-#endif
return (0);
} /* }}} int read_sysfs_callback */
return (0);
} /* }}} int read_sysfs_callback */
@@
-549,7
+556,7
@@
static int read_acpi_full_capacity (char const *dir, /* {{{ */
ssnprintf (filename, sizeof (filename), "%s/%s/info", dir, power_supply);
fh = fopen (filename, "r");
ssnprintf (filename, sizeof (filename), "%s/%s/info", dir, power_supply);
fh = fopen (filename, "r");
- if (
(fh = fopen (filename, "r"))
== NULL)
+ if (
fh
== NULL)
return (errno);
/* last full capacity: 40090 mWh */
return (errno);
/* last full capacity: 40090 mWh */
@@
-608,7
+615,7
@@
static int read_acpi_callback (char const *dir, /* {{{ */
ssnprintf (filename, sizeof (filename), "%s/%s/state", dir, power_supply);
fh = fopen (filename, "r");
ssnprintf (filename, sizeof (filename), "%s/%s/state", dir, power_supply);
fh = fopen (filename, "r");
- if (
(fh = fopen (filename, "r"))
== NULL)
+ if (
fh
== NULL)
{
if ((errno == EAGAIN) || (errno == EINTR) || (errno == ENOENT))
return (0);
{
if ((errno == EAGAIN) || (errno == EINTR) || (errno == ENOENT))
return (0);