From 07db66a6ef857edee2c731d1b66f42a4f32d9622 Mon Sep 17 00:00:00 2001 From: Qiang Huang Date: Thu, 5 Mar 2015 10:21:52 +0800 Subject: [PATCH] fix apply error when we not mount cpu subsystem Find cgroup mountpoint dir through a specific subsystem is not reliable, we don't know which subsystem users will or will not mount, we can't assume that, only we can assume is that users mount cgroup subsystems on the same dir. Signed-off-by: Qiang Huang --- cgroups/fs/apply_raw.go | 4 +--- cgroups/utils.go | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/cgroups/fs/apply_raw.go b/cgroups/fs/apply_raw.go index 4943b775294..3a06e6b917e 100644 --- a/cgroups/fs/apply_raw.go +++ b/cgroups/fs/apply_raw.go @@ -54,12 +54,10 @@ func getCgroupRoot() (string, error) { return cgroupRoot, nil } - // we can pick any subsystem to find the root - cpuRoot, err := cgroups.FindCgroupMountpoint("cpu") + root, err := cgroups.FindCgroupMountpointDir() if err != nil { return "", err } - root := filepath.Dir(cpuRoot) if _, err := os.Stat(root); err != nil { return "", err diff --git a/cgroups/utils.go b/cgroups/utils.go index a360904cce6..c6c400c7d3e 100644 --- a/cgroups/utils.go +++ b/cgroups/utils.go @@ -34,6 +34,21 @@ func FindCgroupMountpoint(subsystem string) (string, error) { return "", NewNotFoundError(subsystem) } +func FindCgroupMountpointDir() (string, error) { + mounts, err := mount.GetMounts() + if err != nil { + return "", err + } + + for _, mount := range mounts { + if mount.Fstype == "cgroup" { + return filepath.Dir(mount.Mountpoint), nil + } + } + + return "", NewNotFoundError("cgroup") +} + type Mount struct { Mountpoint string Subsystems []string