X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fbattery.c;h=c4c050d7ff1cd11cc70cd2d17323f90da747e542;hb=1fc00932fd49fa535551cc4bba09c4e4be059ab4;hp=185442c10d319aa53011b2e1c87f058f28fd254c;hpb=8aad55ab7d737a97d5927458b2b00885e27cae4d;p=collectd.git diff --git a/src/battery.c b/src/battery.c index 185442c1..c4c050d7 100644 --- a/src/battery.c +++ b/src/battery.c @@ -416,10 +416,13 @@ static int sysfs_file_to_buffer(char const *dir, /* {{{ */ if (fgets (buffer, buffer_size, fp) == NULL) { - char errbuf[1024]; 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; } @@ -513,13 +516,15 @@ static int read_sysfs_callback (char const *dir, /* {{{ */ 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 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 */ @@ -551,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"); - if ((fh = fopen (filename, "r")) == NULL) + if (fh == NULL) return (errno); /* last full capacity: 40090 mWh */ @@ -610,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"); - if ((fh = fopen (filename, "r")) == NULL) + if (fh == NULL) { if ((errno == EAGAIN) || (errno == EINTR) || (errno == ENOENT)) return (0);