From c6119da33925fccf6af3f232f7aa7c75de41493b Mon Sep 17 00:00:00 2001 From: Al Tobey Date: Tue, 30 Apr 2013 17:37:43 +0000 Subject: [PATCH] Use /proc/mounts instead of mount(8) Specifically, Ubuntu Precise's cgroup-lite script uses mount -n to mount the cgroup filesystems so they don't appear in mtab, so detection always fails unless the admin updates mtab with /proc/mounts. /proc/mounts is valid on just about every Linux machine in existence and as a bonus is much easier to parse. I also removed the regex in favor of a more accurate parser that should also support monolitic cgroup mounts (e.g. mount -t cgroup none /cgroup). --- utils.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/utils.go b/utils.go index 8bcf38367b..297b798af8 100644 --- a/utils.go +++ b/utils.go @@ -12,7 +12,6 @@ import ( "os" "os/exec" "path/filepath" - "regexp" "runtime" "strings" "sync" @@ -437,17 +436,23 @@ func CompareKernelVersion(a, b *KernelVersionInfo) int { } func FindCgroupMountpoint(cgroupType string) (string, error) { - output, err := exec.Command("mount").CombinedOutput() + output, err := ioutil.ReadFile("/proc/mounts") if err != nil { return "", err } - reg := regexp.MustCompile(`^.* on (.*) type cgroup \(.*` + cgroupType + `[,\)]`) + // /proc/mounts has 6 fields per line, one mount per line, e.g. + // cgroup /sys/fs/cgroup/devices cgroup rw,relatime,devices 0 0 for _, line := range strings.Split(string(output), "\n") { - r := reg.FindStringSubmatch(line) - if len(r) == 2 { - return r[1], nil + parts := strings.Split(line, " ") + if parts[2] == "cgroup" { + for _, opt := range strings.Split(parts[3], ",") { + if opt == cgroupType { + return parts[1], nil + } + } } } + return "", fmt.Errorf("cgroup mountpoint not found for %s", cgroupType) }