diff --git a/src/cgroups/common.rs b/src/cgroups/common.rs index 2658616ed..2dfd6cd86 100644 --- a/src/cgroups/common.rs +++ b/src/cgroups/common.rs @@ -1,6 +1,5 @@ use std::{ env, - ffi::OsStr, fmt::{Debug, Display}, fs::{self, File}, io::{BufRead, BufReader, Write}, @@ -174,16 +173,13 @@ pub fn create_cgroup_manager>( pub fn get_all_pids(path: &Path) -> Result> { log::debug!("scan pids in folder: {:?}", path); let mut result = vec![]; - let proc_str = OsStr::new(CGROUP_PROCS); - walk_path(&path, &mut |p| { - let file_name = p.file_name(); - if let Some(file_name) = file_name { - if file_name == proc_str { - let file = File::open(p)?; - for line in BufReader::new(file).lines() { - if let Ok(line) = line { - result.push(Pid::from_raw(line.parse::()?)) - } + walk_dir(&path, &mut |p| { + let file_path = p.join(CGROUP_PROCS); + if file_path.exists() { + let file = File::open(file_path)?; + for line in BufReader::new(file).lines() { + if let Ok(line) = line { + result.push(Pid::from_raw(line.parse::()?)) } } } @@ -192,18 +188,17 @@ pub fn get_all_pids(path: &Path) -> Result> { Ok(result) } -fn walk_path(path: &Path, c: &mut F) -> Result<()> +fn walk_dir(path: &Path, c: &mut F) -> Result<()> where F: FnMut(&Path) -> Result<()>, { + c(&path)?; for entry in fs::read_dir(path)? { let entry = entry?; let path = entry.path(); if path.is_dir() { - walk_path(&path, c)?; - } else { - c(&path)?; + walk_dir(&path, c)?; } } Ok(())