From 271ca6dc974b562d0e08c927e1fa647f8f854028 Mon Sep 17 00:00:00 2001 From: Guido Falsi Date: Fri, 7 Oct 2016 19:54:35 +0200 Subject: [PATCH] Try more than one sysctl to get CPU temperature. (#330) * Try more than one sysctl to get CPU temperature. Suggested by: walter@pelissero.de Reference: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=210235 * Added braces and using else ifs. --- src/freebsd.cc | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/freebsd.cc b/src/freebsd.cc index 37be1592..94244d66 100644 --- a/src/freebsd.cc +++ b/src/freebsd.cc @@ -426,13 +426,16 @@ double get_acpi_temperature(int fd) int temp; (void)fd; - if (GETSYSCTL("hw.acpi.thermal.tz0.temperature", temp)) { - fprintf(stderr, - "Cannot read sysctl \"hw.acpi.thermal.tz0.temperature\"\n"); - return 0.0; + if (GETSYSCTL("hw.acpi.thermal.tz0.temperature", temp) == 0) { + return KELVTOC(temp); + } else if (GETSYSCTL("dev.cpu.0.temperature", temp) == 0) { + return KELVTOC(temp); + } else if (GETSYSCTL("dev.amdtemp.0.core0.sensor0", temp) == 0) { + return KELVTOC(temp); } + fprintf(stderr, "Cannot get temperature from sysctl\n"); - return KELVTOC(temp); + return 0.0; } static void get_battery_stats(int *battime, int *batcapacity, int *batstate, int *ac) {