diff --git a/Cargo.toml b/Cargo.toml index 3734388..e48a707 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,6 @@ [package] name = "phenix" -description = "Utility to restart PCIe devices when link is lost." -version = "0.2.1" +version = "0.1.3" edition = "2024" license = "GPL-3.0-or-later" repository="https://code.edgarpierre.fr/edpibu/phenix" diff --git a/src/main.rs b/src/main.rs index a9e001c..e13669e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,20 +1,13 @@ #![feature(file_buffered)] -use std::env; use std::fs::File; use std::io::BufRead; use std::io::Write; -use std::io::Seek; -use std::io::SeekFrom; fn main() { println!("Reading kernel messages..."); - let mut kmsg_file = - File::open_buffered(env::var("PHENIX_KMSG").unwrap_or(String::from("/dev/kmsg"))) - .expect("Failed to open /dev/kmsg"); + let kmsg_file = File::open_buffered("/dev/kmsg").expect("Failed to open /dev/kmsg"); - - kmsg_file.seek(SeekFrom::End(0)).expect("Failed to seek to end"); let lines = kmsg_file.lines(); for line in lines { match line { @@ -30,9 +23,8 @@ fn manage_line(line: String) { println!("PCIe link lost {prefix}"); let id = line.splitn(3, " ").nth(1); - match id { - Some(id) => reset_device(id), - None => println!("No device id found in message {line}"), + if let Some(id) = id { + reset_device(id); } } } @@ -41,7 +33,6 @@ fn manage_line(line: String) { fn reset_device(id: &str) { println!("Resetting {id}"); echo1(rm_file_path(&id)); - println!("Removed device {id}"); echo1(String::from("/sys/bus/pci/rescan")); println!("Rescanned PCI bus"); } @@ -53,6 +44,7 @@ fn echo1(path: String) { Ok(mut file) => { file.write_all(b"1") .expect("Failed to write to remove file"); + println!("Removed device {path}"); } } }