mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
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).
This commit is contained in:
parent
cdc2657ee9
commit
c6119da339
1 changed files with 11 additions and 6 deletions
17
utils.go
17
utils.go
|
@ -12,7 +12,6 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
@ -437,17 +436,23 @@ func CompareKernelVersion(a, b *KernelVersionInfo) int {
|
||||||
}
|
}
|
||||||
|
|
||||||
func FindCgroupMountpoint(cgroupType string) (string, error) {
|
func FindCgroupMountpoint(cgroupType string) (string, error) {
|
||||||
output, err := exec.Command("mount").CombinedOutput()
|
output, err := ioutil.ReadFile("/proc/mounts")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
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") {
|
for _, line := range strings.Split(string(output), "\n") {
|
||||||
r := reg.FindStringSubmatch(line)
|
parts := strings.Split(line, " ")
|
||||||
if len(r) == 2 {
|
if parts[2] == "cgroup" {
|
||||||
return r[1], nil
|
for _, opt := range strings.Split(parts[3], ",") {
|
||||||
|
if opt == cgroupType {
|
||||||
|
return parts[1], nil
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return "", fmt.Errorf("cgroup mountpoint not found for %s", cgroupType)
|
return "", fmt.Errorf("cgroup mountpoint not found for %s", cgroupType)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue