From b94fe5b7f88518a00d93f9a9adc45534f48ff4d1 Mon Sep 17 00:00:00 2001 From: Qiang Huang Date: Thu, 10 Sep 2015 08:29:12 +0800 Subject: [PATCH] Fix bug in find cgroup mount point dir Bug was introduced in #250 According to: http://man7.org/linux/man-pages/man5/proc.5.html 36 35 98:0 /mnt1 /mnt2 rw,noatime master:1 - ext3 /dev/root rw,errors=continue (1)(2)(3) (4) (5) (6) (7) (8) (9) (10) (11) ... (7) optional fields: zero or more fields of the form "tag[:value]". The 7th field is optional. We should skip it when parsing mount info. Signed-off-by: Qiang Huang --- libcontainer/cgroups/utils.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/libcontainer/cgroups/utils.go b/libcontainer/cgroups/utils.go index 72a8c014..3a182684 100644 --- a/libcontainer/cgroups/utils.go +++ b/libcontainer/cgroups/utils.go @@ -80,9 +80,15 @@ func FindCgroupMountpointDir() (string, error) { scanner := bufio.NewScanner(f) for scanner.Scan() { - txt := scanner.Text() - fields := strings.Split(txt, " ") - if fields[7] == "cgroup" { + text := scanner.Text() + fields := strings.Split(text, " ") + // Safe as mountinfo encodes mountpoints with spaces as \040. + index := strings.Index(text, " - ") + postSeparatorFields := strings.Fields(text[index+3:]) + if len(postSeparatorFields) < 3 { + return "", fmt.Errorf("Error found less than 3 fields post '-' in %q", text) + } + if postSeparatorFields[0] == "cgroup" { return filepath.Dir(fields[4]), nil } }