Merge pull request #140 from jokemanfire/dev

fix bug: if cgroup path has ":"
This commit is contained in:
Fupan Li
2025-05-29 16:31:14 +08:00
committed by GitHub
2 changed files with 11 additions and 10 deletions

View File

@@ -620,15 +620,16 @@ fn get_cgroups_relative_paths_by_path(path: String) -> Result<HashMap<String, St
let mut m = HashMap::new(); let mut m = HashMap::new();
let content = let content =
fs::read_to_string(path.clone()).map_err(|e| Error::with_cause(ReadFailed(path), e))?; fs::read_to_string(path.clone()).map_err(|e| Error::with_cause(ReadFailed(path), e))?;
for l in content.lines() { // cgroup path may have ":" , likes
let fl: Vec<&str> = l.split(':').collect(); // "2:cpu,cpuacct:/system.slice/containerd.service/test.slice:cri-containerd:96b37a2edf84351487f42039e137427f1812f678850675fac214caf597ee5e4a"
if fl.len() != 3 { for line in content.lines() {
continue; if let Some((first_value_part, remaining_path)) =
} line.split_once(':').unwrap_or_default().1.split_once(':')
{
let keys: Vec<&str> = fl[1].split(',').collect(); let keys: Vec<&str> = first_value_part.split(',').collect();
for key in &keys { keys.iter().for_each(|key| {
m.insert(key.to_string(), fl[2].to_string()); m.insert(key.to_string(), remaining_path.to_string());
});
} }
} }
Ok(m) Ok(m)

View File

@@ -297,7 +297,7 @@ impl DevicesController {
match res { match res {
Ok(_) => { Ok(_) => {
s.lines().fold(Ok(Vec::new()), |acc, line| { s.lines().fold(Ok(Vec::new()), |acc, line| {
let ls = line.to_string().split(|c| c == ' ' || c == ':').map(|x| x.to_string()).collect::<Vec<String>>(); let ls = line.split(|c| c == ' ' || c == ':').map(|x| x.to_string()).collect::<Vec<String>>();
if acc.is_err() || ls.len() != 4 { if acc.is_err() || ls.len() != 4 {
error!("allowed_devices: acc: {:?}, ls: {:?}", acc, ls); error!("allowed_devices: acc: {:?}, ls: {:?}", acc, ls);
Err(Error::new(ParseError)) Err(Error::new(ParseError))