diff --git a/src/cli/debug.rs b/src/cli/debug.rs index eeed61f..240c2fd 100644 --- a/src/cli/debug.rs +++ b/src/cli/debug.rs @@ -219,15 +219,13 @@ fn get_kernel_info() -> Result { /// Get system uptime fn get_system_uptime() -> Result { - let uptime_str = fs::read_to_string("/proc/uptime").map_err(|e| AppError::Io(e))?; + let uptime_str = fs::read_to_string("/proc/uptime").map_err(AppError::Io)?; let uptime_secs = uptime_str .split_whitespace() .next() .ok_or_else(|| AppError::Generic("Invalid format in /proc/uptime file".to_string()))? .parse::() - .map_err(|e| { - AppError::Generic(format!("Failed to parse uptime from /proc/uptime: {}", e)) - })?; + .map_err(|e| AppError::Generic(format!("Failed to parse uptime from /proc/uptime: {e}")))?; Ok(Duration::from_secs_f64(uptime_secs)) } @@ -253,7 +251,16 @@ fn is_systemd_service_active(service_name: &str) -> Result { .output() .map_err(AppError::Io)?; + // Check if the command executed successfully + if !output.status.success() { + // Command failed - service is either not found or not active + return Ok(false); + } + + // Command executed successfully, now check the output content let status = String::from_utf8(output.stdout) .map_err(|e| AppError::Generic(format!("Failed to parse systemctl output: {e}")))?; + + // Explicitly verify the output is "active" Ok(status.trim() == "active") } diff --git a/src/main.rs b/src/main.rs index 7c996a8..6e26645 100644 --- a/src/main.rs +++ b/src/main.rs @@ -464,7 +464,9 @@ fn init_logger() { fn validate_freq(freq_mhz: u32, label: &str) -> Result<(), AppError> { if freq_mhz == 0 { error!("{label} frequency cannot be zero"); - Err(AppError::Generic(format!("{label} frequency cannot be zero"))) + Err(AppError::Generic(format!( + "{label} frequency cannot be zero" + ))) } else if freq_mhz > 10000 { // Extremely high value unlikely to be valid error!("{label} frequency ({freq_mhz} MHz) is unreasonably high");