sane way of finding hwmon path

This commit is contained in:
Drath
2025-05-03 20:19:25 +02:00
parent 6a9cfb1c7c
commit e08f6c8077

View File

@@ -11,8 +11,8 @@ std::string readFile(std::string path, uint8_t trim) {
std::stringstream ss;
std::ifstream fs(path);
if (!fs.good()) {
std::cerr << "Error reading " << path << std::endl;
exit(1);
std::cerr << "[readFile] Error reading " << path << std::endl;
return "";
}
ss << fs.rdbuf();
fs.close();
@@ -34,11 +34,13 @@ int get_val(const std::string &target, const std::string &content) {
}
std::string findHwmonPath(std::string module) {
uint8_t id = 0;
for (; id < 10; id++)
if (readFile("/sys/class/hwmon/hwmon" + std::to_string(id) + "/name") == module) {
for (uint8_t id = 0; id < 10; id++) {
auto f = readFile("/sys/class/hwmon/hwmon" + std::to_string(id) + "/name");
if (f.size() == 0) break;
if (f == module) {
std::cout << ("[Hwmon] Detected " + module + " path is " + "/sys/class/hwmon/hwmon" + std::to_string(id)) << std::endl;
return "/sys/class/hwmon/hwmon" + std::to_string(id);
}
}
return "";
}