diff --git a/cgroups/fs/apply_raw.go b/cgroups/fs/apply_raw.go index e9c06e1e2..2d1a15239 100644 --- a/cgroups/fs/apply_raw.go +++ b/cgroups/fs/apply_raw.go @@ -150,6 +150,10 @@ func (raw *data) parent(subsystem string) (string, error) { } func (raw *data) path(subsystem string) (string, error) { + // If the cgroup name/path is absolute do not look relative to the cgroup of the init process. + if filepath.IsAbs(raw.cgroup) { + return filepath.Join(raw.root, subsystem, raw.cgroup), nil + } parent, err := raw.parent(subsystem) if err != nil { return "", err diff --git a/cgroups/fs/utils_test.go b/cgroups/fs/utils_test.go index 63d743f06..6ea59bc50 100644 --- a/cgroups/fs/utils_test.go +++ b/cgroups/fs/utils_test.go @@ -5,6 +5,8 @@ import ( "os" "path/filepath" "testing" + + "github.com/docker/libcontainer/cgroups" ) const ( @@ -66,3 +68,20 @@ func TestGetCgroupParamsInt(t *testing.T) { t.Fatal("Expecting error, got none") } } + +func TestAbsolutePathHandling(t *testing.T) { + testCgroup := cgroups.Cgroup{ + Name: "bar", + Parent: "/foo", + } + cgroupData := data{ + root: "/sys/fs/cgroup", + cgroup: "/foo/bar", + c: &testCgroup, + pid: 1, + } + expectedPath := filepath.Join(cgroupData.root, "cpu", testCgroup.Parent, testCgroup.Name) + if path, err := cgroupData.path("cpu"); path != expectedPath || err != nil { + t.Fatalf("expected path %s but got %s %s", expectedPath, path, err) + } +}