From 9bebc660423ca974192599a6a5ea8e016a6fe1fc Mon Sep 17 00:00:00 2001 From: Vishnu Kannan Date: Mon, 16 Mar 2015 20:46:28 +0000 Subject: [PATCH] Do not fail cgroups setup if parent cgroup does not exist. Docker-DCO-1.1-Signed-off-by: Vishnu Kannan (github: vishh) --- cgroups/fs/apply_raw.go | 25 +++++++++++-------------- cgroups/fs/cpuset.go | 7 ++----- 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/cgroups/fs/apply_raw.go b/cgroups/fs/apply_raw.go index 7dc24559..f6c0d7d5 100644 --- a/cgroups/fs/apply_raw.go +++ b/cgroups/fs/apply_raw.go @@ -99,11 +99,12 @@ func (m *Manager) Apply(pid int) error { // created then join consists of writing the process pids to cgroup.procs p, err := d.path(name) if err != nil { - if cgroups.IsNotFound(err) { - continue - } return err } + if !cgroups.PathExists(p) { + continue + } + paths[name] = p } m.Paths = paths @@ -173,6 +174,9 @@ func (m *Manager) Freeze(state configs.FreezerState) error { if err != nil { return err } + if !cgroups.PathExists(dir) { + return cgroups.NewNotFoundError("freezer") + } prevState := m.Cgroups.Freezer m.Cgroups.Freezer = state @@ -197,6 +201,9 @@ func (m *Manager) GetPids() ([]int, error) { if err != nil { return nil, err } + if !cgroups.PathExists(dir) { + return nil, cgroups.NewNotFoundError("devices") + } return cgroups.ReadProcsFile(dir) } @@ -237,17 +244,7 @@ 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) { - path := filepath.Join(raw.root, subsystem, raw.cgroup) - - if _, err := os.Stat(path); err != nil { - if os.IsNotExist(err) { - return "", cgroups.NewNotFoundError(subsystem) - } - - return "", err - } - - return path, nil + return filepath.Join(raw.root, subsystem, raw.cgroup), nil } parent, err := raw.parent(subsystem) diff --git a/cgroups/fs/cpuset.go b/cgroups/fs/cpuset.go index 75f38cd2..d8465a66 100644 --- a/cgroups/fs/cpuset.go +++ b/cgroups/fs/cpuset.go @@ -17,12 +17,9 @@ type CpusetGroup struct { func (s *CpusetGroup) Apply(d *data) error { dir, err := d.path("cpuset") if err != nil { - if cgroups.IsNotFound(err) { - return nil - } else { - return err - } + return err } + return s.ApplyDir(dir, d.c, d.pid) }