Skip to content

Commit f4ddea3

Browse files
authored
Merge pull request #359 from kolyshkin/simparse
cgroupv2: simplify parseCgroupFile
2 parents 285db17 + 4be65db commit f4ddea3

File tree

1 file changed

+3
-10
lines changed

1 file changed

+3
-10
lines changed

cgroup2/utils.go

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -135,16 +135,9 @@ func parseCgroupFile(path string) (string, error) {
135135
func parseCgroupFromReader(r io.Reader) (string, error) {
136136
s := bufio.NewScanner(r)
137137
for s.Scan() {
138-
var (
139-
text = s.Text()
140-
parts = strings.SplitN(text, ":", 3)
141-
)
142-
if len(parts) < 3 {
143-
return "", fmt.Errorf("invalid cgroup entry: %q", text)
144-
}
145-
// text is like "0::/user.slice/user-1001.slice/session-1.scope"
146-
if parts[0] == "0" && parts[1] == "" {
147-
return parts[2], nil
138+
// "0::/user.slice/user-1001.slice/session-1.scope"
139+
if path, ok := strings.CutPrefix(s.Text(), "0::"); ok {
140+
return path, nil
148141
}
149142
}
150143
if err := s.Err(); err != nil {

0 commit comments

Comments
 (0)