netstar pushed a commit to branch master.

http://git.enlightenment.org/apps/evisum.git/commit/?id=d1d4d0fb9e983cd8b2800d6601395123539830db

commit d1d4d0fb9e983cd8b2800d6601395123539830db
Author: Alastair Poole <nets...@gmail.com>
Date:   Sat Jul 11 17:23:34 2020 +0100

    openbsd: fix for non-acpi batteries
---
 src/bin/system/machine.h             |  5 ++-
 src/bin/system/machine/cpu.bogox     |  6 ++++
 src/bin/system/machine/sensors.bogox | 62 +++++++++++++++++++++---------------
 3 files changed, 47 insertions(+), 26 deletions(-)

diff --git a/src/bin/system/machine.h b/src/bin/system/machine.h
index 5b1d6a6..a9583cc 100644
--- a/src/bin/system/machine.h
+++ b/src/bin/system/machine.h
@@ -86,7 +86,10 @@ void
 system_info_all_free(Sys_Info *);
 
 int
-system_cpu_online_count_get();
+system_cpu_online_count_get(void);
+
+int
+system_cpu_count_get(void);
 
 cpu_core_t **
 system_cpu_usage_get(int *ncpu);
diff --git a/src/bin/system/machine/cpu.bogox b/src/bin/system/machine/cpu.bogox
index 1c5066f..2e56c7f 100644
--- a/src/bin/system/machine/cpu.bogox
+++ b/src/bin/system/machine/cpu.bogox
@@ -60,6 +60,12 @@ cpu_count(void)
    return cores;
 }
 
+int
+system_cpu_count_get(void)
+{
+   return cpu_count();
+}
+
 int
 system_cpu_online_count_get(void)
 {
diff --git a/src/bin/system/machine/sensors.bogox 
b/src/bin/system/machine/sensors.bogox
index 0e5cba0..fbb6829 100644
--- a/src/bin/system/machine/sensors.bogox
+++ b/src/bin/system/machine/sensors.bogox
@@ -118,12 +118,15 @@ _power_battery_count_get(power_t *power)
 {
 #if defined(__OpenBSD__)
    struct sensordev snsrdev;
+   struct sensor snsr;
+   size_t slen = sizeof(struct sensor);
    size_t sdlen = sizeof(struct sensordev);
-   int mib[5] = { CTL_HW, HW_SENSORS, 0, 0, 0 };
-   int i, devn, id;
+   int mibs[5] = { CTL_HW, HW_SENSORS, 0, 0, 0 };
+   int i, devn;
+
    for (devn = 0;; devn++) {
-        mib[2] = devn;
-        if (sysctl(mib, 3, &snsrdev, &sdlen, NULL, 0) == -1)
+        mibs[2] = devn;
+        if (sysctl(mibs, 3, &snsrdev, &sdlen, NULL, 0) == -1)
           {
              if (errno == ENXIO)
                continue;
@@ -131,31 +134,40 @@ _power_battery_count_get(power_t *power)
                break;
           }
 
-        for (i = 0; i < 10; i++) {
-             char buf[64];
-             snprintf(buf, sizeof(buf), "acpibat%d", i);
-             if (!strcmp(buf, snsrdev.xname))
-               {
-                  id = power->battery_count;
-                  power->batteries = realloc(power->batteries, 1 +
-                                     power->battery_count * sizeof(bat_t **));
-                  power->batteries[id] = calloc(1, sizeof(bat_t));
-                  power->batteries[id]->name = strdup(buf);
-                  power->batteries[id]->present = true;
-                  power->batteries[id]->mibs = malloc(sizeof(int) * 5);
-                  int *tmp = power->batteries[id]->mibs;
-                  tmp[0] = mib[0];
-                  tmp[1] = mib[1];
-                  tmp[2] = mib[2];
-                  power->battery_count++;
-               }
+        for (int n = 0; n < snsrdev.maxnumt[SENSOR_WATTHOUR]; n++) {
+             mibs[4] = n;
+
+             if (sysctl(mibs, 5, &snsr, &slen, NULL, 0) == -1)
+               continue;
+
+             if (slen > 0 && (snsr.flags & SENSOR_FINVALID) == 0)
+               break;
+          }
+
+        if (sysctl(mibs, 5, &snsr, &slen, NULL, 0) == -1)
+          continue;
+
+        if ((snsr.type == SENSOR_AMPHOUR) || (snsr.type == SENSOR_WATTHOUR))
+          {
+             i = power->battery_count;
+             power->batteries = realloc(power->batteries, 1 +
+                                power->battery_count++ * sizeof(bat_t **));
+             power->batteries[i] = calloc(1, sizeof(bat_t));
+             power->batteries[i]->name = strdup(snsrdev.xname);
+             power->batteries[i]->present = true;
+             power->batteries[i]->mibs = malloc(sizeof(int) * 5);
+
+             int *tmp = power->batteries[i]->mibs;
+             tmp[0] = mibs[0];
+             tmp[1] = mibs[1];
+             tmp[2] = mibs[2];
           }
 
         if (!strcmp("acpiac0", snsrdev.xname))
           {
-             power->ac_mibs[0] = mib[0];
-             power->ac_mibs[1] = mib[1];
-             power->ac_mibs[2] = mib[2];
+             power->ac_mibs[0] = mibs[0];
+             power->ac_mibs[1] = mibs[1];
+             power->ac_mibs[2] = mibs[2];
           }
      }
 #elif defined(__FreeBSD__) || defined(__DragonFly__)

-- 


Reply via email to