Skip to content

Commit 9b4053e

Browse files
committed
Chore: remove temps_linux
1 parent b4325ff commit 9b4053e

File tree

7 files changed

+74
-89
lines changed

7 files changed

+74
-89
lines changed

CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,6 @@ if(LINUX)
480480
src/detection/gtk_qt/qt.c
481481
src/detection/sound/sound_linux.c
482482
src/detection/swap/swap_linux.c
483-
src/detection/temps/temps_linux.c
484483
src/detection/terminalfont/terminalfont_linux.c
485484
src/detection/terminalshell/terminalshell_linux.c
486485
src/detection/terminalsize/terminalsize_linux.c
@@ -544,7 +543,6 @@ elseif(ANDROID)
544543
src/detection/processes/processes_linux.c
545544
src/detection/sound/sound_nosupport.c
546545
src/detection/swap/swap_linux.c
547-
src/detection/temps/temps_linux.c
548546
src/detection/terminalfont/terminalfont_android.c
549547
src/detection/terminalshell/terminalshell_linux.c
550548
src/detection/terminalsize/terminalsize_linux.c

src/detection/battery/battery_linux.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#include "battery.h"
22
#include "common/io/io.h"
3-
#include "detection/temps/temps_linux.h"
43
#include "util/stringUtils.h"
54

65
#include <dirent.h>

src/detection/cpu/cpu_linux.c

Lines changed: 74 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,85 @@
22
#include "common/io/io.h"
33
#include "common/processing.h"
44
#include "common/properties.h"
5-
#include "detection/temps/temps_linux.h"
65
#include "util/mallocHelper.h"
76
#include "util/stringUtils.h"
87

98
#include <sys/sysinfo.h>
109
#include <stdlib.h>
1110
#include <unistd.h>
11+
#include <dirent.h>
12+
13+
static double parseHwmonDir(FFstrbuf* dir, FFstrbuf* buffer)
14+
{
15+
//https://www.kernel.org/doc/Documentation/hwmon/sysfs-interface
16+
uint32_t dirLength = dir->length;
17+
ffStrbufAppendS(dir, "temp1_input");
18+
19+
if(!ffReadFileBuffer(dir->chars, buffer))
20+
{
21+
// Some badly implemented system put temp file in /hwmonN/device
22+
ffStrbufSubstrBefore(dir, dirLength);
23+
ffStrbufAppendS(dir, "device/");
24+
dirLength = dir->length;
25+
ffStrbufAppendS(dir, "temp1_input");
26+
27+
if(!ffReadFileBuffer(dir->chars, buffer))
28+
return 0.0/0.0;
29+
}
30+
31+
ffStrbufSubstrBefore(dir, dirLength);
32+
33+
double value = ffStrbufToDouble(buffer);// millidegree Celsius
34+
35+
if(value != value)
36+
return 0.0/0.0;
37+
38+
ffStrbufAppendS(dir, "name");
39+
if (!ffReadFileBuffer(dir->chars, buffer))
40+
return 0.0/0.0;
41+
42+
ffStrbufTrimRightSpace(buffer);
43+
44+
if(
45+
ffStrbufContainS(buffer, "cpu") ||
46+
ffStrbufEqualS(buffer, "k10temp") || // AMD
47+
ffStrbufEqualS(buffer, "coretemp") // Intel
48+
) return value / 1000.;
49+
50+
return false;
51+
}
52+
53+
static double detectCPUTemp(void)
54+
{
55+
FF_STRBUF_AUTO_DESTROY baseDir = ffStrbufCreateA(64);
56+
ffStrbufAppendS(&baseDir, "/sys/class/hwmon/");
57+
58+
FF_STRBUF_AUTO_DESTROY buffer = ffStrbufCreate();
59+
60+
uint32_t baseDirLength = baseDir.length;
61+
62+
FF_AUTO_CLOSE_DIR DIR* dirp = opendir(baseDir.chars);
63+
if(dirp == NULL)
64+
return 0.0/0.0;
65+
66+
struct dirent* entry;
67+
while((entry = readdir(dirp)) != NULL)
68+
{
69+
if(entry->d_name[0] == '.')
70+
continue;
71+
72+
ffStrbufAppendS(&baseDir, entry->d_name);
73+
ffStrbufAppendC(&baseDir, '/');
74+
75+
double result = parseHwmonDir(&baseDir, &buffer);
76+
if (result == result)
77+
return result;
78+
79+
ffStrbufSubstrBefore(&baseDir, baseDirLength);
80+
}
81+
82+
return 0.0/0.0;
83+
}
1284

1385
#ifdef __ANDROID__
1486
#include "common/settings.h"
@@ -358,7 +430,7 @@ const char* ffDetectCPUImpl(const FFCPUOptions* options, FFCPUResult* cpu)
358430
if(cpuinfo == NULL)
359431
return "fopen(\"/proc/cpuinfo\", \"r\") failed";
360432

361-
cpu->temperature = options->temp ? ffDetectCPUTemp() : FF_CPU_TEMP_UNSET;
433+
cpu->temperature = options->temp ? detectCPUTemp() : FF_CPU_TEMP_UNSET;
362434

363435
FF_STRBUF_AUTO_DESTROY physicalCoresBuffer = ffStrbufCreate();
364436
FF_STRBUF_AUTO_DESTROY cpuMHz = ffStrbufCreate();

src/detection/gpu/gpu_linux.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#include "detection/gpu/gpu.h"
22
#include "detection/vulkan/vulkan.h"
3-
#include "detection/temps/temps_linux.h"
43
#include "detection/cpu/cpu.h"
54
#include "detection/gpu/gpu_driver_specific.h"
65
#include "common/io/io.h"

src/detection/physicaldisk/physicaldisk_linux.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#include "physicaldisk.h"
22
#include "common/io/io.h"
33
#include "common/properties.h"
4-
#include "detection/temps/temps_linux.h"
54
#include "util/stringUtils.h"
65

76
#include <ctype.h>

src/detection/temps/temps_linux.c

Lines changed: 0 additions & 77 deletions
This file was deleted.

src/detection/temps/temps_linux.h

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)