aboutsummaryrefslogtreecommitdiffstats
path: root/src/modules/temperature/tempget.c
diff options
context:
space:
mode:
authorDaniel Kolesa <d.kolesa@samsung.com>2015-04-13 11:02:33 +0100
committerDaniel Kolesa <d.kolesa@samsung.com>2015-04-13 11:02:33 +0100
commit4389030678cd44989825eda7b0c7a3b2fa0c9cbc (patch)
tree439ebdc99f774f133c1b1b390194956359c6a7a5 /src/modules/temperature/tempget.c
parente-comp-wl: Remove unused variable (diff)
downloadenlightenment-4389030678cd44989825eda7b0c7a3b2fa0c9cbc.tar.gz
tempget: Add more temperature sources for FreeBSD
Summary: Not all motherboards have 'hw.acpi.thermal.tz0.temperature' sensor. Fallback to 'dev.cpu.0.temperature' (provided by coretemp(4) or amdtemp(4)), or 'dev.aibs.0.temp.0' (aibs(4)) (per suggestion of Dmitry Luhtionov). Test Plan: Ran `src/modules/temperature/tempget` manually with some debugging printfs and various sensors commented out. I can only test tz0 and dev.cpu (coretemp(4)) on my system. Reviewers: zmike, q66 Reviewed By: q66 Subscribers: seoz Projects: #enlightenment-git Differential Revision: https://phab.enlightenment.org/D2335
Diffstat (limited to 'src/modules/temperature/tempget.c')
-rw-r--r--src/modules/temperature/tempget.c44
1 files changed, 33 insertions, 11 deletions
diff --git a/src/modules/temperature/tempget.c b/src/modules/temperature/tempget.c
index b03334125..a2e05a2f7 100644
--- a/src/modules/temperature/tempget.c
+++ b/src/modules/temperature/tempget.c
@@ -6,6 +6,7 @@
#ifdef __FreeBSD__
# include <sys/types.h>
# include <sys/sysctl.h>
+# include <errno.h>
#endif
#ifdef __OpenBSD__
@@ -28,7 +29,17 @@ static int cur_poll_interval = 32;
static char *sensor_path = NULL;
#if defined (__FreeBSD__) || defined (__OpenBSD__)
-static int mib[5];
+static int mib[CTL_MAXNAME];
+#endif
+#ifdef __FreeBSD__
+static unsigned miblen;
+static const char *sources[] =
+ {
+ "hw.acpi.thermal.tz0.temperature",
+ "dev.cpu.0.temperature",
+ "dev.aibs.0.temp.0",
+ NULL
+ };
#endif
#ifdef __OpenBSD__
@@ -95,7 +106,9 @@ init(void)
Eina_List *therms;
char path[PATH_MAX];
#ifdef __FreeBSD__
+ unsigned i;
size_t len;
+ int rc;
#endif
if ((!sensor_type) || ((!sensor_name) || (sensor_name[0] == 0)))
@@ -103,9 +116,16 @@ init(void)
E_FREE(sensor_name);
E_FREE(sensor_path);
#ifdef __FreeBSD__
- /* TODO: FreeBSD can also have more temperature sensors! */
- sensor_type = SENSOR_TYPE_FREEBSD;
- sensor_name = strdup("tz0");
+ for (i = 0; sources[i]; i++)
+ {
+ rc = sysctlbyname(sources[i], NULL, NULL, NULL, 0);
+ if (rc == 0)
+ {
+ sensor_type = SENSOR_TYPE_FREEBSD;
+ sensor_name = strdup(sources[i]);
+ break;
+ }
+ }
#elif __OpenBSD__
mib[0] = CTL_HW;
mib[1] = HW_SENSORS;
@@ -270,11 +290,13 @@ init(void)
case SENSOR_TYPE_FREEBSD:
#ifdef __FreeBSD__
- snprintf(path, sizeof(path), "hw.acpi.thermal.%s.temperature",
- sensor_name);
- sensor_path = strdup(path);
- len = 5;
- sysctlnametomib(sensor_path, mib, &len);
+ len = sizeof(mib) / sizeof(mib[0]);
+ rc = sysctlnametomib(sensor_name, mib, &len);
+ if (rc == 0)
+ {
+ miblen = len;
+ sensor_path = strdup(sensor_name);
+ }
#endif
break;
@@ -394,8 +416,8 @@ check(void)
case SENSOR_TYPE_FREEBSD:
#ifdef __FreeBSD__
- len = sizeof(temp);
- if (sysctl(mib, 5, &ftemp, &len, NULL, 0) != -1)
+ len = sizeof(ftemp);
+ if (sysctl(mib, miblen, &ftemp, &len, NULL, 0) == 0)
{
temp = (ftemp - 2732) / 10;
ret = 1;