aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZach Scott <ethhics@gmail.com>2019-09-19 17:08:36 +0000
committerDan Cross <crossd@gmail.com>2019-09-19 13:08:36 -0400
commit7d827b5cca185b411be3ac9b71834958f4737bdf (patch)
tree62b22f261f75d32463703674ef42f92cb1a6daf3
parente995a0c101863688d5f14649ae3de45a7c43789c (diff)
downloadplan9port-7d827b5cca185b411be3ac9b71834958f4737bdf.tar.gz
plan9port-7d827b5cca185b411be3ac9b71834958f4737bdf.tar.bz2
plan9port-7d827b5cca185b411be3ac9b71834958f4737bdf.zip
auxstats: replace /proc ACPI calls with /sys ones (#245)
According to <https://askubuntu.com/a/309146>, use of `/proc/acpi` to get battery usage is deprecated. This commit replaces the two files from this API with the single file `/sys/class/power_supply/BAT0/capacity`, simultaneously removing the need to calculate battery percentage.
-rw-r--r--src/cmd/auxstats/Linux.c30
1 files changed, 8 insertions, 22 deletions
diff --git a/src/cmd/auxstats/Linux.c b/src/cmd/auxstats/Linux.c
index 09ca18f3..64c86a26 100644
--- a/src/cmd/auxstats/Linux.c
+++ b/src/cmd/auxstats/Linux.c
@@ -26,36 +26,22 @@ void (*statfn[])(int) =
void
xapm(int first)
{
- static int fd = -1, fdb = -1;
- int i, last = -1, curr = -1;
+ static int fd = -1;
+ int curr = -1;
if(first){
- fd = open("/proc/acpi/battery/BAT0/info", OREAD);
- fdb = open("/proc/acpi/battery/BAT0/state", OREAD);
+ fd = open("/sys/class/power_supply/BAT0/capacity", OREAD);
return;
}
- if(fd == -1 || fdb == -1)
+ if(fd == -1)
return;
readfile(fd);
- for(i=0; i<nline; i++){
- tokens(i);
- if(ntok < 3)
- continue;
- if(strcmp(tok[0], "last") == 0 && strcmp(tok[1], "full") == 0)
- last = atoi(tok[3]);
- }
- readfile(fdb);
- for(i = 0; i < nline; i++) {
- tokens(i);
- if(ntok < 3)
- continue;
- if(strcmp(tok[0], "remaining") == 0 && strcmp(tok[1], "capacity:") == 0)
- curr = atoi(tok[2]);
- }
+ tokens(0);
+ curr = atoi(tok[0]);
- if(curr != -1 && last != -1)
- Bprint(&bout, "battery =%d 100\n", (int)(((float)curr/(float)last)*100.0));
+ if(curr != -1)
+ Bprint(&bout, "battery =%d 100\n", curr);
}