make sys sensor reading more robust

This commit is contained in:
2025-12-13 21:19:48 +01:00
parent d4691c7bf2
commit cd94018426

View File

@@ -2,6 +2,7 @@
#include <chrono>
#include <format>
#include <log.hpp>
#include <string>
#include <sys.hpp>
#include <utils.hpp>
@@ -51,10 +52,18 @@ void sys::getNetwork(Network* net, const std::string& device) {
}
void sys::detectHwmon(sysSensors* s, const std::string& platform) {
s->hwmon = getFirstDir("/sys/devices/platform/" + platform + "/hwmon");
// we dont really need getFirstDir since its a static folder, but its useful for try/catch
try {
s->hwmon = getFirstDir("/sys/devices/platform/" + platform + "/hwmon");
} catch (...) {
log(LOG::ERR, "sys::detectHwmon", "Can't open sys hwmon. Module loaded? Kernel params added?");
return;
}
}
void sys::updateSensors(sysSensors* s) {
if(s->hwmon.length() < 1)
return;
static char buf[8];
fastReadNum(s->hwmon + "/fan2_input", s->fan_speed[0]);
fastReadNum(s->hwmon + "/fan7_input", s->fan_speed[1]);