Skip to content

Commit 504271a

Browse files
committed
libct/cg: move GetAllPids out of utils.go
This is just moving the code around to ease the code review, no other changes. Signed-off-by: Kir Kolyshkin <[email protected]>
1 parent 8772c4d commit 504271a

File tree

2 files changed

+30
-22
lines changed

2 files changed

+30
-22
lines changed

libcontainer/cgroups/getallpids.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// +build linux
2+
3+
package cgroups
4+
5+
import (
6+
"os"
7+
"path/filepath"
8+
)
9+
10+
// GetAllPids returns all pids, that were added to cgroup at path and to all its
11+
// subcgroups.
12+
func GetAllPids(path string) ([]int, error) {
13+
var pids []int
14+
// collect pids from all sub-cgroups
15+
err := filepath.Walk(path, func(p string, info os.FileInfo, iErr error) error {
16+
if iErr != nil {
17+
return iErr
18+
}
19+
if info.IsDir() || info.Name() != CgroupProcesses {
20+
return nil
21+
}
22+
cPids, err := readProcsFile(p)
23+
if err != nil {
24+
return err
25+
}
26+
pids = append(pids, cPids...)
27+
return nil
28+
})
29+
return pids, err
30+
}

libcontainer/cgroups/utils.go

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -339,28 +339,6 @@ func GetPids(dir string) ([]int, error) {
339339
return readProcsFile(filepath.Join(dir, CgroupProcesses))
340340
}
341341

342-
// GetAllPids returns all pids, that were added to cgroup at path and to all its
343-
// subcgroups.
344-
func GetAllPids(path string) ([]int, error) {
345-
var pids []int
346-
// collect pids from all sub-cgroups
347-
err := filepath.Walk(path, func(p string, info os.FileInfo, iErr error) error {
348-
if iErr != nil {
349-
return iErr
350-
}
351-
if info.IsDir() || info.Name() != CgroupProcesses {
352-
return nil
353-
}
354-
cPids, err := readProcsFile(p)
355-
if err != nil {
356-
return err
357-
}
358-
pids = append(pids, cPids...)
359-
return nil
360-
})
361-
return pids, err
362-
}
363-
364342
// WriteCgroupProc writes the specified pid into the cgroup's cgroup.procs file
365343
func WriteCgroupProc(dir string, pid int) error {
366344
// Normally dir should not be empty, one case is that cgroup subsystem

0 commit comments

Comments
 (0)