From 30ffa4bdd2db809924e3d27bd8bb09f0314e12ec Mon Sep 17 00:00:00 2001 From: Carter Li Date: Mon, 23 Sep 2024 16:36:32 +0800 Subject: [PATCH] Temps (Linux): simplify --- src/detection/temps/temps_linux.c | 42 ++++++++----------------------- src/detection/temps/temps_linux.h | 2 -- 2 files changed, 11 insertions(+), 33 deletions(-) diff --git a/src/detection/temps/temps_linux.c b/src/detection/temps/temps_linux.c index 89d9f941e..1816e4ca3 100644 --- a/src/detection/temps/temps_linux.c +++ b/src/detection/temps/temps_linux.c @@ -10,12 +10,19 @@ static bool parseHwmonDir(FFstrbuf* dir, FFTempValue* value) { //https://www.kernel.org/doc/Documentation/hwmon/sysfs-interface uint32_t dirLength = dir->length; + ffStrbufAppendS(dir, "temp1_input"); FF_STRBUF_AUTO_DESTROY valueBuffer = ffStrbufCreate(); - - ffStrbufAppendS(dir, "temp1_input"); if(!ffReadFileBuffer(dir->chars, &valueBuffer)) - return false; + { + // Some badly implemented system put temp file in /hwmonN/device + ffStrbufSubstrBefore(dir, dirLength); + ffStrbufAppendS(dir, "/device"); + dirLength = dir->length; + + if(!ffReadFileBuffer(dir->chars, &valueBuffer)) + return false; + } ffStrbufSubstrBefore(dir, dirLength); @@ -29,33 +36,7 @@ static bool parseHwmonDir(FFstrbuf* dir, FFTempValue* value) ffStrbufTrimRightSpace(&value->name); ffStrbufSubstrBefore(dir, dirLength); - ffStrbufAppendS(dir, "device/class"); - if(!ffReadFileBuffer(dir->chars, &valueBuffer)) - { - ffStrbufSubstrBefore(dir, dirLength); - ffStrbufAppendS(dir, "device/device/class"); - ffReadFileBuffer(dir->chars, &valueBuffer); - } - ffStrbufTrimRightSpace(&valueBuffer); - ffStrbufSubstrBefore(dir, dirLength); - if(valueBuffer.length) - value->deviceClass = (uint32_t) strtoul(valueBuffer.chars, NULL, 16); - - ffStrbufClear(&valueBuffer); - ffStrbufEnsureFree(&valueBuffer, 64); - ffStrbufAppendS(dir, "device"); - ssize_t linkLen = readlink(dir->chars, valueBuffer.chars, valueBuffer.allocated - 1); - if (linkLen > 0) - { - valueBuffer.length = (uint32_t) linkLen; - valueBuffer.chars[linkLen] = 0; - ffStrbufSubstrAfterLastC(&valueBuffer, '/'); - ffStrbufInitMove(&value->deviceName, &valueBuffer); - } - else - ffStrbufInit(&value->deviceName); - - return value->name.length > 0 || value->deviceClass > 0; + return true; } const FFlist* ffDetectTemps(void) @@ -87,7 +68,6 @@ const FFlist* ffDetectTemps(void) FFTempValue* temp = ffListAdd(&result); ffStrbufInit(&temp->name); - temp->deviceClass = 0; if(!parseHwmonDir(&baseDir, temp)) { ffStrbufDestroy(&temp->name); diff --git a/src/detection/temps/temps_linux.h b/src/detection/temps/temps_linux.h index ccb908b44..e8887c56e 100644 --- a/src/detection/temps/temps_linux.h +++ b/src/detection/temps/temps_linux.h @@ -5,8 +5,6 @@ typedef struct FFTempValue { FFstrbuf name; - FFstrbuf deviceName; - uint32_t deviceClass; double value; } FFTempValue;