Return NotFound error for cgroups abs paths
Signed-off-by: Michael Crosby <michael@docker.com>
This commit is contained in:
parent
edfe81a08b
commit
4aa9963faf
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue