Skip to content

Commit 547fb08

Browse files
authored
Merge pull request #140 from jokemanfire/dev
fix bug: if cgroup path has ":"
2 parents ec9f354 + 7d4d457 commit 547fb08

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

src/cgroup.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -620,15 +620,16 @@ fn get_cgroups_relative_paths_by_path(path: String) -> Result<HashMap<String, St
620620
let mut m = HashMap::new();
621621
let content =
622622
fs::read_to_string(path.clone()).map_err(|e| Error::with_cause(ReadFailed(path), e))?;
623-
for l in content.lines() {
624-
let fl: Vec<&str> = l.split(':').collect();
625-
if fl.len() != 3 {
626-
continue;
627-
}
628-
629-
let keys: Vec<&str> = fl[1].split(',').collect();
630-
for key in &keys {
631-
m.insert(key.to_string(), fl[2].to_string());
623+
// cgroup path may have ":" , likes
624+
// "2:cpu,cpuacct:/system.slice/containerd.service/test.slice:cri-containerd:96b37a2edf84351487f42039e137427f1812f678850675fac214caf597ee5e4a"
625+
for line in content.lines() {
626+
if let Some((first_value_part, remaining_path)) =
627+
line.split_once(':').unwrap_or_default().1.split_once(':')
628+
{
629+
let keys: Vec<&str> = first_value_part.split(',').collect();
630+
keys.iter().for_each(|key| {
631+
m.insert(key.to_string(), remaining_path.to_string());
632+
});
632633
}
633634
}
634635
Ok(m)

src/devices.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ impl DevicesController {
297297
match res {
298298
Ok(_) => {
299299
s.lines().fold(Ok(Vec::new()), |acc, line| {
300-
let ls = line.to_string().split(|c| c == ' ' || c == ':').map(|x| x.to_string()).collect::<Vec<String>>();
300+
let ls = line.split(|c| c == ' ' || c == ':').map(|x| x.to_string()).collect::<Vec<String>>();
301301
if acc.is_err() || ls.len() != 4 {
302302
error!("allowed_devices: acc: {:?}, ls: {:?}", acc, ls);
303303
Err(Error::new(ParseError))

0 commit comments

Comments
 (0)