Skip to content

Commit 20fb8bc

Browse files
committed
Don't hard-code temp1_input
1 parent aaed86f commit 20fb8bc

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/utils/cpu.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,22 @@ static CPU_TEMPERATURE_PATH: LazyLock<Option<PathBuf>> = LazyLock::new(|| {
4747
cpu_temperature_path.map(|(_, path)| path)
4848
});
4949

50+
fn search_for_first_temp<S: AsRef<str>>(base_path: S) -> Option<PathBuf> {
51+
glob(&format!("{}/temp*_input", base_path.as_ref()))
52+
.unwrap()
53+
.flatten()
54+
.next()
55+
}
56+
5057
/// Looks for hwmons with the given names.
5158
/// This function is a bit inefficient since the `names` array is considered to be ordered by priority.
5259
fn search_for_hwmons(names: &[&'static str]) -> Option<(&'static str, PathBuf)> {
5360
for temp_name in names {
5461
for path in (glob("/sys/class/hwmon/hwmon*").unwrap()).flatten() {
5562
if let Ok(read_name) = std::fs::read_to_string(path.join("name")) {
5663
if &read_name.trim_end() == temp_name {
57-
return Some((temp_name, path.join("temp1_input")));
64+
return search_for_first_temp(path.to_string_lossy())
65+
.map(|first_temp| (*temp_name, first_temp));
5866
}
5967
}
6068
}

0 commit comments

Comments
 (0)