Skip to content

Commit

Permalink
fix bug: if cgroup path has ":"
Browse files Browse the repository at this point in the history
This bug is occur in cgroup path "which has :"

Signed-off-by: jokemanfire <[email protected]>
  • Loading branch information
jokemanfire committed Nov 2, 2024
1 parent eb3e37a commit 7d4d457
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
19 changes: 10 additions & 9 deletions src/cgroup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -620,15 +620,16 @@ fn get_cgroups_relative_paths_by_path(path: String) -> Result<HashMap<String, St
let mut m = HashMap::new();
let content =
fs::read_to_string(path.clone()).map_err(|e| Error::with_cause(ReadFailed(path), e))?;
for l in content.lines() {
let fl: Vec<&str> = l.split(':').collect();
if fl.len() != 3 {
continue;
}

let keys: Vec<&str> = fl[1].split(',').collect();
for key in &keys {
m.insert(key.to_string(), fl[2].to_string());
// cgroup path may have ":" , likes
// "2:cpu,cpuacct:/system.slice/containerd.service/test.slice:cri-containerd:96b37a2edf84351487f42039e137427f1812f678850675fac214caf597ee5e4a"
for line in content.lines() {
if let Some((first_value_part, remaining_path)) =
line.split_once(':').unwrap_or_default().1.split_once(':')
{
let keys: Vec<&str> = first_value_part.split(',').collect();
keys.iter().for_each(|key| {
m.insert(key.to_string(), remaining_path.to_string());
});
}
}
Ok(m)
Expand Down
2 changes: 1 addition & 1 deletion src/devices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ impl DevicesController {
match res {
Ok(_) => {
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 {
error!("allowed_devices: acc: {:?}, ls: {:?}", acc, ls);
Err(Error::new(ParseError))
Expand Down

0 comments on commit 7d4d457

Please sign in to comment.