Skip to content

Commit

Permalink
tikv_util: cgroup path parsing fix (#14537)
Browse files Browse the repository at this point in the history
close #14538

Signed-off-by: Spade A <u6748471@anu.edu.au>
  • Loading branch information
SpadeA-Tang committed Apr 7, 2023
1 parent 83ce091 commit 4199ed9
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions components/tikv_util/src/sys/cgroup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,15 +183,19 @@ fn is_cgroup2_unified_mode() -> Result<bool, String> {
//
// The format is "<id>:<hierarchy>:<path>". For example,
// "10:cpuset:/test-cpuset".
//
// Note: path may contains ":" in some envrionment.
fn parse_proc_cgroup_v1(lines: &str) -> HashMap<String, String> {
let mut subsystems = HashMap::new();
for line in lines.lines().map(|s| s.trim()).filter(|s| !s.is_empty()) {
let mut iter = line.split(':');
if let Some(_id) = iter.next() {
if let Some(systems) = iter.next() {
if let Some(path) = iter.next() {
// If the path itself contains ":", we need to concat them
let path = iter.collect::<Vec<_>>().join(":");
if !path.is_empty() {
for system in systems.split(',') {
subsystems.insert(system.to_owned(), path.to_owned());
subsystems.insert(system.to_owned(), path.clone());
}
continue;
}
Expand Down Expand Up @@ -697,4 +701,19 @@ mod tests {
.unwrap();
assert!(child.wait().unwrap().success());
}

#[test]
fn test_cgroup_path_with_semicolon() {
let id = "1";
let devices = "test_device";
let path = "/dir1:dir2:dir3";
let mut lines = String::new();
lines.push_str(id);
lines.push(':');
lines.push_str(devices);
lines.push(':');
lines.push_str(path);
let ret = parse_proc_cgroup_v1(&lines);
assert_eq!(ret.get(devices).unwrap(), path);
}
}

0 comments on commit 4199ed9

Please sign in to comment.