aboutsummaryrefslogtreecommitdiffstats
path: root/src/modules/temperature/tempget.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules/temperature/tempget.c')
-rw-r--r--src/modules/temperature/tempget.c61
1 files changed, 60 insertions, 1 deletions
diff --git a/src/modules/temperature/tempget.c b/src/modules/temperature/tempget.c
index bbe2556e2..7a403cc5a 100644
--- a/src/modules/temperature/tempget.c
+++ b/src/modules/temperature/tempget.c
@@ -11,6 +11,14 @@
# include <sys/sysctl.h>
#endif
+#ifdef __OpenBSD__
+#include <sys/param.h>
+#include <sys/sysctl.h>
+#include <sys/sensors.h>
+#include <errno.h>
+#include <err.h>
+#endif
+
#include <Ecore.h>
#include <Ecore_File.h>
@@ -22,9 +30,18 @@ static int poll_interval = 32;
static int cur_poll_interval = 32;
static char *sensor_path = NULL;
-#ifdef __FreeBSD__
+#if defined (__FreeBSD__) || defined (__OpenBSD__)
static int mib[5];
#endif
+
+#ifdef __OpenBSD__
+static int dev, numt;
+static struct sensordev snsrdev;
+static size_t sdlen = sizeof(snsrdev);
+static struct sensor snsr;
+static size_t slen = sizeof(snsr);
+#endif
+
static Ecore_Poller *poller = NULL;
static int ptemp = 0;
@@ -93,6 +110,24 @@ init(void)
/* TODO: FreeBSD can also have more temperature sensors! */
sensor_type = SENSOR_TYPE_FREEBSD;
sensor_name = strdup("tz0");
+#elif __OpenBSD__
+ mib[0] = CTL_HW;
+ mib[1] = HW_SENSORS;
+
+ for (dev = 0; ; dev++) {
+ mib[2] = dev;
+ if (sysctl(mib, 3, &snsrdev, &sdlen, NULL, 0) == -1) {
+ if (errno == ENOENT) /* no further sensors */
+ break;
+ else
+ continue;
+ }
+ if (strcmp(snsrdev.xname, "cpu0") == 0) {
+ sensor_type = SENSOR_TYPE_OPENBSD;
+ sensor_name = strdup("cpu0");
+ break;
+ }
+ }
#else
therms = ecore_file_ls("/proc/acpi/thermal_zone");
if (therms)
@@ -235,6 +270,20 @@ init(void)
sysctlnametomib(sensor_path, mib, &len);
#endif
break;
+ case SENSOR_TYPE_OPENBSD:
+#ifdef __OpenBSD__
+ for (numt = 0; numt < snsrdev.maxnumt[SENSOR_TEMP]; numt++) {
+ mib[4] = numt;
+ slen = sizeof(snsr);
+ if (sysctl(mib, 5, &snsr, &slen, NULL, 0) == -1)
+ continue;
+ if (slen > 0 && (snsr.flags & SENSOR_FINVALID) == 0) {
+ break;
+ }
+ }
+#endif
+
+ break;
case SENSOR_TYPE_OMNIBOOK:
sensor_path = strdup("/proc/omnibook/temperature");
break;
@@ -335,6 +384,16 @@ check(void)
goto error;
#endif
break;
+ case SENSOR_TYPE_OPENBSD:
+#ifdef __OpenBSD__
+ if (sysctl(mib, 5, &snsr, &slen, NULL, 0) != -1) {
+ temp = (snsr.value - 273150000) / 1000000.0;
+ ret = 1;
+ }
+ else
+ goto error;
+#endif
+ break;
case SENSOR_TYPE_OMNIBOOK:
f = fopen(sensor_path, "r");
if (f)