Skip to content

Commit fe19473

Browse files
committed
Ignore unified paths with no subsystem
Signed-off-by: Michael Crosby <[email protected]>
1 parent 7461ec9 commit fe19473

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

paths_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,27 @@ func TestRootPath(t *testing.T) {
6060
t.Errorf("expected / but received %q", p)
6161
}
6262
}
63+
64+
func TestEmptySubsystem(t *testing.T) {
65+
const data = `10:devices:/user.slice
66+
9:net_cls,net_prio:/
67+
8:blkio:/
68+
7:freezer:/
69+
6:perf_event:/
70+
5:cpuset:/
71+
4:memory:/
72+
3:pids:/user.slice/user-1000.slice/[email protected]
73+
2:cpu,cpuacct:/
74+
1:name=systemd:/user.slice/user-1000.slice/[email protected]/gnome-terminal-server.service
75+
0::/user.slice/user-1000.slice/[email protected]/gnome-terminal-server.service`
76+
r := strings.NewReader(data)
77+
paths, err := parseCgroupFromReader(r)
78+
if err != nil {
79+
t.Fatal(err)
80+
}
81+
for subsystem, path := range paths {
82+
if subsystem == "" {
83+
t.Fatalf("empty subsystem for %q", path)
84+
}
85+
}
86+
}

utils.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,9 @@ func parseCgroupFromReader(r io.Reader) (map[string]string, error) {
207207
return nil, fmt.Errorf("invalid cgroup entry: must contain at least two colons: %v", text)
208208
}
209209
for _, subs := range strings.Split(parts[1], ",") {
210-
cgroups[subs] = parts[2]
210+
if subs != "" {
211+
cgroups[subs] = parts[2]
212+
}
211213
}
212214
}
213215
return cgroups, nil

0 commit comments

Comments
 (0)