From 4aa9963faf09d870a0879806fa52f4a61c2cf1ce Mon Sep 17 00:00:00 2001 From: Michael Crosby Date: Wed, 20 Aug 2014 10:14:56 -0700 Subject: [PATCH] Return NotFound error for cgroups abs paths Signed-off-by: Michael Crosby --- cgroups/fs/apply_raw.go | 14 +++++++++++++- cgroups/fs/utils_test.go | 19 ------------------- 2 files changed, 13 insertions(+), 20 deletions(-) diff --git a/cgroups/fs/apply_raw.go b/cgroups/fs/apply_raw.go index e20cdbb9..64ad8c84 100644 --- a/cgroups/fs/apply_raw.go +++ b/cgroups/fs/apply_raw.go @@ -168,12 +168,24 @@ func (raw *data) Paths() (map[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 + path := filepath.Join(raw.root, subsystem, raw.cgroup) + + if _, err := os.Stat(path); err != nil { + if os.IsNotExist(err) { + return "", cgroups.ErrNotFound + } + + return "", err + } + + return path, nil } + parent, err := raw.parent(subsystem) if err != nil { return "", err } + return filepath.Join(parent, raw.cgroup), nil } diff --git a/cgroups/fs/utils_test.go b/cgroups/fs/utils_test.go index 6ea59bc5..63d743f0 100644 --- a/cgroups/fs/utils_test.go +++ b/cgroups/fs/utils_test.go @@ -5,8 +5,6 @@ import ( "os" "path/filepath" "testing" - - "github.com/docker/libcontainer/cgroups" ) const ( @@ -68,20 +66,3 @@ 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) - } -}