Debian Codegraph @

src/collection/linux/utils.rs

raw symbols SCIP
1 use std::{fs, path::Path};
2
3 /// Whether the temperature should *actually* be read during enumeration.
4 /// Will return false if the state is not D0/unknown, or if it does not support
5 /// `device/power_state`.
6 ///
7 /// `path` is a path to the device itself (e.g.
8 /// `/sys/class/hwmon/hwmon1/device`).
9 #[inline]
10 pub fn is_device_awake(device: &Path) -> bool {
11 // Whether the temperature should *actually* be read during enumeration.
12 // Set to false if the device is in ACPI D3cold.
13 // Documented at https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-devices-power_state
14 let power_state = device.join("power_state");
15 if power_state.exists() {
16 if let Ok(state) = fs::read_to_string(power_state) {
17 let state = state.trim();
18 // The zenpower3 kernel module (incorrectly?) reports "unknown", causing this
19 // check to fail and temperatures to appear as zero instead of
20 // having the file not exist.
21 //
22 // Their self-hosted git instance has disabled sign up, so this bug can't be
23 // reported either.
24 state == "D0" || state == "unknown"
25 } else {
26 true
27 }
28 } else {
29 true
30 }
31 }