()
| 220 | } |
| 221 | |
| 222 | func getCgroupPathForCurrentProcess() (string, error) { |
| 223 | path := fmt.Sprintf("/proc/%d/cgroup", os.Getpid()) |
| 224 | f, err := os.Open(path) |
| 225 | if err != nil { |
| 226 | return "", err |
| 227 | } |
| 228 | defer f.Close() |
| 229 | |
| 230 | cgroupPath := "" |
| 231 | s := bufio.NewScanner(f) |
| 232 | for s.Scan() { |
| 233 | text := s.Text() |
| 234 | procEntries := strings.SplitN(text, "::", 2) |
| 235 | // set process cgroupPath only if entry is valid |
| 236 | if len(procEntries) > 1 { |
| 237 | cgroupPath = procEntries[1] |
| 238 | } |
| 239 | } |
| 240 | if err := s.Err(); err != nil { |
| 241 | return cgroupPath, err |
| 242 | } |
| 243 | return cgroupPath, nil |
| 244 | } |
| 245 | |
| 246 | // getCgroupv1Path is a helper function to get the cgroup v1 path |
| 247 | func (c *CgroupControl) getCgroupv1Path(name string) string { |
no test coverage detected
searching dependent graphs…