parseCgroupString parses each line of the /proc/[pid]/cgroup file Line format is hierarchyID:[controller1,controller2]:path.
(cgroupStr string)
| 47 | // parseCgroupString parses each line of the /proc/[pid]/cgroup file |
| 48 | // Line format is hierarchyID:[controller1,controller2]:path. |
| 49 | func parseCgroupString(cgroupStr string) (*Cgroup, error) { |
| 50 | var err error |
| 51 | |
| 52 | fields := strings.SplitN(cgroupStr, ":", 3) |
| 53 | if len(fields) < 3 { |
| 54 | return nil, fmt.Errorf("%w: 3+ fields required, found %d fields in cgroup string: %s", ErrFileParse, len(fields), cgroupStr) |
| 55 | } |
| 56 | |
| 57 | cgroup := &Cgroup{ |
| 58 | Path: fields[2], |
| 59 | Controllers: nil, |
| 60 | } |
| 61 | cgroup.HierarchyID, err = strconv.Atoi(fields[0]) |
| 62 | if err != nil { |
| 63 | return nil, fmt.Errorf("%w: hierarchy ID: %q", ErrFileParse, fields[0]) |
| 64 | } |
| 65 | if fields[1] != "" { |
| 66 | ssNames := strings.Split(fields[1], ",") |
| 67 | cgroup.Controllers = append(cgroup.Controllers, ssNames...) |
| 68 | } |
| 69 | return cgroup, nil |
| 70 | } |
| 71 | |
| 72 | // parseCgroups reads each line of the /proc/[pid]/cgroup file. |
| 73 | func parseCgroups(data []byte) ([]Cgroup, error) { |
no outgoing calls
searching dependent graphs…