From bfb55312bebdea2b3db340b452d26fee589a4827 Mon Sep 17 00:00:00 2001 From: Christophe de Dinechin Date: Mon, 25 Mar 2024 16:48:28 +0100 Subject: [PATCH 1/3] agent: Fix `.enumerate` errors during `make check` Running `make check` in the `src/agent` directory gives: ``` error: you seem to use `.enumerate()` and immediately discard the index --> rustjail/src/mount.rs:572:27 | 572 | for (_index, line) in reader.lines().enumerate() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unused_enumerate_index = note: `-D clippy::unused-enumerate-index` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::unused_enumerate_index)]` help: remove the `.enumerate()` call | 572 | for line in reader.lines() { | ~~~~ ~~~~~~~~~~~~~~ Checking tokio-native-tls v0.3.1 Checking hyper-tls v0.5.0 Checking reqwest v0.11.18 error: could not compile `rustjail` (lib) due to 1 previous error warning: build failed, waiting for other jobs to finish... make: *** [../../utils.mk:177: standard_rust_check] Error 101 ``` Fixes: #9342 Signed-off-by: Christophe de Dinechin --- src/agent/rustjail/src/mount.rs | 2 +- src/agent/src/mount.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/agent/rustjail/src/mount.rs b/src/agent/rustjail/src/mount.rs index 0b80718df3..92a8d0dad9 100644 --- a/src/agent/rustjail/src/mount.rs +++ b/src/agent/rustjail/src/mount.rs @@ -569,7 +569,7 @@ pub fn parse_mount_table(mountinfo_path: &str) -> Result> { let reader = BufReader::new(file); let mut infos = Vec::new(); - for (_index, line) in reader.lines().enumerate() { + for line in reader.lines() { let line = line?; //Example mountinfo format: diff --git a/src/agent/src/mount.rs b/src/agent/src/mount.rs index e7bbf96f8d..6836087a9c 100644 --- a/src/agent/src/mount.rs +++ b/src/agent/src/mount.rs @@ -180,7 +180,7 @@ pub fn get_mount_fs_type_from_file(mount_file: &str, mount_point: &str) -> Resul let re = Regex::new(format!("device .+ mounted on {} with fstype (.+)", mount_point).as_str())?; // Read the file line by line using the lines() iterator from std::io::BufRead. - for (_index, line) in content.lines().enumerate() { + for line in content.lines() { if let Some(capes) = re.captures(line) { if capes.len() > 1 { return Ok(capes[1].to_string()); @@ -225,7 +225,7 @@ pub fn get_cgroup_mounts( // #subsys_name hierarchy num_cgroups enabled // fields[0] fields[1] fields[2] fields[3] - 'outer: for (_, line) in reader.lines().enumerate() { + 'outer: for line in reader.lines() { let line = line?; let fields: Vec<&str> = line.split('\t').collect(); From df5c88cdf0db1b08c740391223509169d34a01fb Mon Sep 17 00:00:00 2001 From: Christophe de Dinechin Date: Mon, 25 Mar 2024 16:55:05 +0100 Subject: [PATCH 2/3] agent: Remove lint error about `.flatten` running forever The lint report is the following: ``` error: `flatten()` will run forever if the iterator repeatedly produces an `Err` --> src/rpc.rs:1754:10 | 1754 | .flatten() | ^^^^^^^^^ help: replace with: `map_while(Result::ok)` | note: this expression returning a `std::io::Lines` may produce an infinite number of `Err` in case of a read error --> src/rpc.rs:1752:5 | 1752 | / reader 1753 | | .lines() | |________________^ = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#lines_filter_map_ok = note: `-D clippy::lines-filter-map-ok` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::lines_filter_map_ok)]` ``` This commit simply applies the suggestion. Fixes: #9342 Signed-off-by: Christophe de Dinechin --- src/agent/src/rpc.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/agent/src/rpc.rs b/src/agent/src/rpc.rs index 38b6f161a9..5c95dcfbeb 100644 --- a/src/agent/src/rpc.rs +++ b/src/agent/src/rpc.rs @@ -1746,7 +1746,7 @@ fn is_signal_handled(proc_status_file: &str, signum: u32) -> bool { // read lines start with SigBlk/SigIgn/SigCgt and check any match the signal mask reader .lines() - .flatten() + .map_while(Result::ok) .filter(|line| { line.starts_with("SigBlk:") || line.starts_with("SigIgn:") From 82c4079fd016e340abe025ae71ef4e7624f9342a Mon Sep 17 00:00:00 2001 From: Christophe de Dinechin Date: Mon, 25 Mar 2024 16:56:41 +0100 Subject: [PATCH 3/3] agent: Remove useless loop This is the report from `make check`: ``` error: this loop never actually loops --> src/signal.rs:147:9 | 147 | / loop { 148 | | select! { 149 | | _ = handle => { 150 | | println!("INFO: task completed"); ... | 156 | | } 157 | | } | |_________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#never_loop = note: `#[deny(clippy::never_loop)]` on by default ``` There is only one option: you get something or a timeout. You never retry, so the report is correct. Fixes: #9342 Signed-off-by: Christophe de Dinechin --- src/agent/src/signal.rs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/agent/src/signal.rs b/src/agent/src/signal.rs index 62a2193719..f5c3ced91f 100644 --- a/src/agent/src/signal.rs +++ b/src/agent/src/signal.rs @@ -144,15 +144,12 @@ mod tests { tx.send(true).expect("failed to request shutdown"); - loop { - select! { - _ = handle => { - println!("INFO: task completed"); - break; - }, - _ = &mut timeout => { - panic!("signal thread failed to stop"); - } + select! { + _ = handle => { + println!("INFO: task completed"); + }, + _ = &mut timeout => { + panic!("signal thread failed to stop"); } } }