From 08a92a4324ff8ffe9efa4bfd1cc88764448f3786 Mon Sep 17 00:00:00 2001 From: Carter Li Date: Sun, 10 Nov 2024 13:28:48 +0800 Subject: [PATCH] CPU (OpenBSD): support CPU temp detection --- src/detection/cpu/cpu_obsd.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/detection/cpu/cpu_obsd.c b/src/detection/cpu/cpu_obsd.c index 04d550198..298f064d6 100644 --- a/src/detection/cpu/cpu_obsd.c +++ b/src/detection/cpu/cpu_obsd.c @@ -1,6 +1,9 @@ #include "cpu.h" #include "common/sysctl.h" +#include +#include + const char* ffDetectCPUImpl(const FFCPUOptions* options, FFCPUResult* cpu) { if (ffSysctlGetString(CTL_HW, HW_MODEL, &cpu->name)) @@ -13,7 +16,14 @@ const char* ffDetectCPUImpl(const FFCPUOptions* options, FFCPUResult* cpu) ffCPUDetectSpeedByCpuid(cpu); cpu->frequencyBase = (uint32_t) ffSysctlGetInt(CTL_HW, HW_CPUSPEED, 0); - cpu->temperature = FF_CPU_TEMP_UNSET; // HW_SENSORS? + cpu->temperature = FF_CPU_TEMP_UNSET; + if (options->temp) + { + struct sensor sensors; + size_t size = sizeof(sensors); + if (sysctl((int[]) {CTL_HW, HW_SENSORS, 0, SENSOR_TEMP, 0}, 5, &sensors, &size, NULL, 0) == 0) + cpu->temperature = (double) (sensors.value - 273150000) / 1E6; + } return NULL; }