Skip to content

Commit

Permalink
Handle process cgroup paths containng ':'
Browse files Browse the repository at this point in the history
Cgroup paths containing ':' will cause `Process::cgroups` to return an
incomplete pathname. The reason is that parsing the fields in
`/proc/self/cgroup` is perform with `.split(':')`. If something as
follows is set:

```bash
mkdir /sys/fs/cgroup/memory/foo:bar
echo $$ > /sys/fs/cgroup/memory/foo:bar/tasks
cat /proc/self/cgroup
...
8:memory:/foo:bar
...
```

the resulting `ProcessCgroup` will have a `pathname` equal to just `/foo`.

This patch addresses this by taking the remainer of the line after the
second ':' as the pathname. This is safe because `cgroups(7)` describes
`/proc/self/cgroup` as only having 3 fields.
  • Loading branch information
Alfonso Ros committed Oct 14, 2021
1 parent 8e1cc16 commit 5b4207c
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/cgroups.rs
Expand Up @@ -102,7 +102,7 @@ impl Process {
continue;
}

let mut s = line.split(':');
let mut s = line.splitn(3, ':');
let hierarchy = from_str!(u32, expect!(s.next(), "hierarchy"));
let controllers = expect!(s.next(), "controllers")
.split(',')
Expand Down

0 comments on commit 5b4207c

Please sign in to comment.