code most copy from https://github.com/opencontainers/runc
()
| 87 | |
| 88 | // code most copy from https://github.com/opencontainers/runc |
| 89 | func getCgroupPath() (map[string]string, error) { |
| 90 | cgroupPath := make(map[string]string) |
| 91 | f, err := os.Open("/proc/self/mountinfo") |
| 92 | if err != nil { |
| 93 | return nil, err |
| 94 | } |
| 95 | defer f.Close() |
| 96 | |
| 97 | scanner := bufio.NewScanner(f) |
| 98 | for scanner.Scan() { |
| 99 | text := scanner.Text() |
| 100 | fields := strings.Split(text, " ") |
| 101 | // Safe as mountinfo encodes mountpoints with spaces as \040. |
| 102 | _, after, _ := strings.Cut(text, " - ") |
| 103 | postSeparatorFields := strings.Fields(after) |
| 104 | numPostFields := len(postSeparatorFields) |
| 105 | |
| 106 | // This is an error as we can't detect if the mount is for "cgroup" |
| 107 | if numPostFields == 0 { |
| 108 | continue |
| 109 | } |
| 110 | |
| 111 | if postSeparatorFields[0] == "cgroup" { |
| 112 | // Check that the mount is properly formatted. |
| 113 | if numPostFields < 3 { |
| 114 | continue |
| 115 | } |
| 116 | cgroupPath[filepath.Base(fields[4])] = fields[4] |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | return cgroupPath, nil |
| 121 | } |
| 122 | |
| 123 | // TestDaemonCustomCgroup ensures plugin.cgroup.path is not ignored |
| 124 | func TestDaemonCustomCgroup(t *testing.T) { |
no test coverage detected
searching dependent graphs…