From 220e5098a8c15303daf3de660d2c02c139d28e9a Mon Sep 17 00:00:00 2001 From: Qiang Huang Date: Tue, 30 Aug 2016 14:12:15 +0800 Subject: [PATCH] Fix default cgroup path Alternative of #895 , part of #892 The intension of current behavior if to create cgroup in parent cgroup of current process, but we did this in a wrong way, we used devices cgroup path of current process as the default parent path for all subsystems, this is wrong because we don't always have the same cgroup path for all subsystems. Signed-off-by: Qiang Huang --- libcontainer/specconv/spec_linux.go | 12 ++---------- libcontainer/specconv/spec_linux_test.go | 5 ++--- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/libcontainer/specconv/spec_linux.go b/libcontainer/specconv/spec_linux.go index 856371c69..2dfd8b5df 100644 --- a/libcontainer/specconv/spec_linux.go +++ b/libcontainer/specconv/spec_linux.go @@ -12,7 +12,6 @@ import ( "syscall" "time" - "github.com/opencontainers/runc/libcontainer/cgroups" "github.com/opencontainers/runc/libcontainer/configs" "github.com/opencontainers/runc/libcontainer/seccomp" libcontainerUtils "github.com/opencontainers/runc/libcontainer/utils" @@ -253,10 +252,7 @@ func createLibcontainerMount(cwd string, m specs.Mount) *configs.Mount { } func createCgroupConfig(name string, useSystemdCgroup bool, spec *specs.Spec) (*configs.Cgroup, error) { - var ( - err error - myCgroupPath string - ) + var myCgroupPath string c := &configs.Cgroup{ Resources: &configs.Resources{}, @@ -287,11 +283,7 @@ func createCgroupConfig(name string, useSystemdCgroup bool, spec *specs.Spec) (* } } else { if myCgroupPath == "" { - myCgroupPath, err = cgroups.GetThisCgroupDir("devices") - if err != nil { - return nil, err - } - myCgroupPath = filepath.Join(myCgroupPath, name) + c.Name = name } c.Path = myCgroupPath } diff --git a/libcontainer/specconv/spec_linux_test.go b/libcontainer/specconv/spec_linux_test.go index 3b7c6b78c..a4c4495e3 100644 --- a/libcontainer/specconv/spec_linux_test.go +++ b/libcontainer/specconv/spec_linux_test.go @@ -3,7 +3,6 @@ package specconv import ( - "strings" "testing" "github.com/opencontainers/runtime-spec/specs-go" @@ -33,7 +32,7 @@ func TestLinuxCgroupsPathNotSpecified(t *testing.T) { t.Errorf("Couldn't create Cgroup config: %v", err) } - if !strings.HasSuffix(cgroup.Path, "/ContainerID") { - t.Errorf("Wrong cgroupsPath, expected it to have suffix '%s' got '%s'", "/ContainerID", cgroup.Path) + if cgroup.Path != "" { + t.Errorf("Wrong cgroupsPath, expected it to be empty string, got '%s'", cgroup.Path) } }