From 5b4207cdf7e909b5d7b0e8cc83c73bd1a80a7ffe Mon Sep 17 00:00:00 2001 From: Alfonso Ros Date: Thu, 14 Oct 2021 10:57:30 +0200 Subject: [PATCH] Handle process cgroup paths containng ':' 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. --- src/cgroups.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cgroups.rs b/src/cgroups.rs index 83dcdced..fe61f033 100644 --- a/src/cgroups.rs +++ b/src/cgroups.rs @@ -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(',')