Browse Source

Merge pull request #488 from tobert/cgroups-via-proc-mounts

* runtime: Use /proc/mounts instead of mount(8)
Guillaume J. Charmes 12 years ago
parent
commit
62a595da5c
1 changed files with 11 additions and 6 deletions
  1. 11 6
      utils.go

+ 11 - 6
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)
 }