Return NotFound error for cgroups abs paths

Signed-off-by: Michael Crosby <michael@docker.com>
This commit is contained in:
Michael Crosby 2014-08-20 10:14:56 -07:00
parent edfe81a08b
commit 4aa9963faf
2 changed files with 13 additions and 20 deletions

View File

@ -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
}

View File

@ -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)
}
}