diff --git a/CHANGELOG.md b/CHANGELOG.md index 93508e7..b020938 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,13 +10,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 _Changes in the next release_ ### Fixed -- Misplaced text sensors in custom panels (#11). -- Wrong start position for circular progress (fan) sensor using a counter-clockwise direction (#12). +- Misplaced text sensors in custom panels ([#11](https://github.com/zehnm/aoostar-rs/issues/11)). +- Wrong start position for circular progress (fan) sensor using a counter-clockwise direction ([#12](https://github.com/zehnm/aoostar-rs/issues/12)). +- sysinfo tool: make sensor file world-readable, create all parent directories. ### Added -- Simple sensor panel with a file-based data source (#6). -- Initial support for fan-, progress-, & pointer-sensors (#8). -- Use [mdBook](https://rust-lang.github.io/mdBook/) for documentation and publish user guide to GitHub pages (#10). +- Simple sensor panel with a file-based data source ([#6](https://github.com/zehnm/aoostar-rs/issues/6)). +- Initial support for fan-, progress-, & pointer-sensors ([#8](https://github.com/zehnm/aoostar-rs/pull/8)). +- Use [mdBook](https://rust-lang.github.io/mdBook/) for documentation and publish user guide to GitHub pages ([#10](https://github.com/zehnm/aoostar-rs/pull/10)). ### Changed - Project structure using a Cargo workspace. diff --git a/crates/sysinfo/src/main.rs b/crates/sysinfo/src/main.rs index 8727c58..5169284 100644 --- a/crates/sysinfo/src/main.rs +++ b/crates/sysinfo/src/main.rs @@ -14,12 +14,13 @@ use std::collections::HashMap; use std::fmt::Display; use std::fs; use std::io::{BufWriter, Write}; +use std::os::unix::fs::PermissionsExt; use std::path::{Path, PathBuf}; use std::process::{Command, exit}; use std::thread::sleep; use std::time::{Duration, Instant}; use sysinfo::{Components, DiskKind, Disks, Networks, System}; -use tempfile::NamedTempFile; +use tempfile::{Builder, NamedTempFile}; /// Proof of concept sensor value collection for the asterctl screen control tool. #[derive(Parser, Debug)] @@ -65,6 +66,9 @@ fn main() -> Result<(), Box> { #[cfg(not(target_os = "linux"))] let use_smartctl = false; + if let Some(out_file) = &args.out && let Some(parent) = out_file.parent() { + fs::create_dir_all(parent)?; + } let mut sensors = HashMap::with_capacity(64); let mut sysinfo_source = SysinfoSource::new(); @@ -76,6 +80,10 @@ fn main() -> Result<(), Box> { update_linux_storage_sensors(&mut sensors, use_smartctl)?; } + if !refresh.is_zero() { + info!("Starting sysinfo with refresh={}ms", refresh.as_millis()); + } + loop { let upd_start_time = Instant::now(); @@ -123,13 +131,19 @@ fn write_sensor_file( exit(1); } + // make sure our sensor file can be read by everyone + let all_read_perm = fs::Permissions::from_mode(0o664); let tmp_file = if let Some(temp_path) = temp_dir { fs::create_dir_all(temp_path)?; - NamedTempFile::new_in(temp_path)? + + debug!("Creating a new named temp file in {temp_path:?}"); + Builder::new().permissions(all_read_perm).tempfile_in(temp_path)? } else { - NamedTempFile::new()? + debug!("Creating a new named temp file"); + Builder::new().permissions(all_read_perm).tempfile()? }; + debug!("Writing sensor temp file..."); let mut stream = BufWriter::new(&tmp_file); for (label, value) in sensors.iter() { @@ -138,6 +152,7 @@ fn write_sensor_file( stream.flush()?; drop(stream); + debug!("Renaming temp file to: {out_file:?}"); tmp_file.persist(out_file)?; Ok(())