Skip to content

Commit

Permalink
Ignore unified paths with no subsystem
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Crosby <[email protected]>
  • Loading branch information
crosbymichael committed Jul 10, 2017
1 parent 7461ec9 commit fe19473
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
24 changes: 24 additions & 0 deletions paths_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,27 @@ func TestRootPath(t *testing.T) {
t.Errorf("expected / but received %q", p)
}
}

func TestEmptySubsystem(t *testing.T) {
const data = `10:devices:/user.slice
9:net_cls,net_prio:/
8:blkio:/
7:freezer:/
6:perf_event:/
5:cpuset:/
4:memory:/
3:pids:/user.slice/user-1000.slice/[email protected]
2:cpu,cpuacct:/
1:name=systemd:/user.slice/user-1000.slice/[email protected]/gnome-terminal-server.service
0::/user.slice/user-1000.slice/[email protected]/gnome-terminal-server.service`
r := strings.NewReader(data)
paths, err := parseCgroupFromReader(r)
if err != nil {
t.Fatal(err)
}
for subsystem, path := range paths {
if subsystem == "" {
t.Fatalf("empty subsystem for %q", path)
}
}
}
4 changes: 3 additions & 1 deletion utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,9 @@ func parseCgroupFromReader(r io.Reader) (map[string]string, error) {
return nil, fmt.Errorf("invalid cgroup entry: must contain at least two colons: %v", text)
}
for _, subs := range strings.Split(parts[1], ",") {
cgroups[subs] = parts[2]
if subs != "" {
cgroups[subs] = parts[2]
}
}
}
return cgroups, nil
Expand Down

0 comments on commit fe19473

Please sign in to comment.