readCGroup attempts to determine the cgroup for the container by reading the fields of /proc/self/cgroup (third field) We currently only check the first line of /proc/self/cgroup.
(ctx context.Context)
| 127 | // reading the fields of /proc/self/cgroup (third field) |
| 128 | // We currently only check the first line of /proc/self/cgroup. |
| 129 | func ReadCGroupSelf(ctx context.Context) (string, error) { |
| 130 | fs := GetFS(ctx) |
| 131 | raw, err := afero.ReadFile(fs, "/proc/self/cgroup") |
| 132 | if err != nil { |
| 133 | return "", xerrors.Errorf("read /proc/self/cgroup: %w", err) |
| 134 | } |
| 135 | |
| 136 | lines := bytes.Split(raw, []byte("\n")) |
| 137 | if len(lines) == 0 { |
| 138 | return "", xerrors.Errorf("unexpected content of /proc/self/cgroup: %s", string(raw)) |
| 139 | } |
| 140 | |
| 141 | // Just pick the first line. |
| 142 | line := lines[0] |
| 143 | fields := bytes.Split(line, []byte(":")) |
| 144 | if len(fields) != 3 { |
| 145 | return "", xerrors.Errorf("expected 3 fields in last line of /proc/self/cgroup: %s", string(raw)) |
| 146 | } |
| 147 | |
| 148 | return string(fields[2]), nil |
| 149 | } |
no test coverage detected