0 | |
Description: Rewrite to skip "AC" battery reported by libaci.
|
1 | |
This get the program working again using current libaci with
|
2 | |
recent kernels. Workaround for bug #479096 in libacpi.
|
3 | |
Author: Petter Reinholdtsen <pere@debian.org>
|
4 | |
Bug-Debian: https://bugs.debian.org/574678
|
5 | |
Forwarded: no
|
6 | |
Reviewed-By: Petter Reinholdtsen <pere@hungry.com>
|
7 | |
Last-Update: 2016-03-11
|
8 | |
|
9 | |
--- battery-stats-0.3.6.orig/src/battery-stats-collector.c
|
10 | |
+++ battery-stats-0.3.6/src/battery-stats-collector.c
|
11 | |
@@ -26,6 +26,7 @@
|
12 | |
#include <getopt.h>
|
13 | |
#include <errno.h>
|
14 | |
#include <time.h>
|
15 | |
+#include <assert.h>
|
16 | |
#include <apm.h>
|
17 | |
#include <syslog.h>
|
18 | |
|
19 | |
@@ -59,12 +60,24 @@ static void show_usage(void);
|
20 | |
static char *myname = "battery-stats-collector";
|
21 | |
static char *myversion = "0.3.3";
|
22 | |
|
23 | |
-static int battery_num = 0;
|
24 | |
+static int battery_num = -1;
|
25 | |
|
26 | |
static int do_syslog = 0;
|
27 | |
#define COMPLAIN(loglevel, args...) if (do_syslog) syslog(loglevel, ## args); \
|
28 | |
else { fprintf(stderr,"%s: ", myname); fprintf(stderr, ##args); }
|
29 | |
|
30 | |
+static int first_battery_num(global_t *libacpi_global)
|
31 | |
+{
|
32 | |
+ int i;
|
33 | |
+ assert(NULL != libacpi_global);
|
34 | |
+ for (i = 0; i < libacpi_global->batt_count; ++i) {
|
35 | |
+ if (0 != strcmp("AC", batteries[i].name)) {
|
36 | |
+ return i;
|
37 | |
+ }
|
38 | |
+ }
|
39 | |
+ return -1;
|
40 | |
+}
|
41 | |
+
|
42 | |
int main(int argc, char **argv)
|
43 | |
{
|
44 | |
int sample_interval_secs = 30;
|
45 | |
@@ -201,6 +214,13 @@ int main(int argc, char **argv)
|
46 | |
COMPLAIN(LOG_INFO, "Number of batteries: %i.\n",
|
47 | |
libacpi_global->batt_count);
|
48 | |
if (libacpi_global->batt_count > 1) {
|
49 | |
+ /*
|
50 | |
+ * Make sure to skip "battery" AC, which is the power
|
51 | |
+ * socket and not a battery.
|
52 | |
+ */
|
53 | |
+ if (-1 == battery_num) {
|
54 | |
+ battery_num = first_battery_num(libacpi_global);
|
55 | |
+ }
|
56 | |
COMPLAIN(LOG_INFO,
|
57 | |
"Reading info from battery %d only.\n", battery_num);
|
58 | |
}
|