Skip to content

Commit 363468d

Browse files
committed
libct/cg: improve GetAllPids and readProcsFile
Since every cgroup directory is guaranteed to have cgroup.procs file, we don't have to do filename comparison in GetAllPids() and just read cgroup.procs in every directory. While at it, switch readProcsFile to use our own OpenFile. Signed-off-by: Kir Kolyshkin <[email protected]>
1 parent 504271a commit 363468d

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

libcontainer/cgroups/getallpids.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func GetAllPids(path string) ([]int, error) {
1616
if iErr != nil {
1717
return iErr
1818
}
19-
if info.IsDir() || info.Name() != CgroupProcesses {
19+
if !info.IsDir() {
2020
return nil
2121
}
2222
cPids, err := readProcsFile(p)

libcontainer/cgroups/utils.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ func GetAllSubsystems() ([]string, error) {
118118
return subsystems, nil
119119
}
120120

121-
func readProcsFile(file string) ([]int, error) {
122-
f, err := os.Open(file)
121+
func readProcsFile(dir string) ([]int, error) {
122+
f, err := OpenFile(dir, CgroupProcesses, os.O_RDONLY)
123123
if err != nil {
124124
return nil, err
125125
}
@@ -336,7 +336,7 @@ func getHugePageSizeFromFilenames(fileNames []string) ([]string, error) {
336336

337337
// GetPids returns all pids, that were added to cgroup at path.
338338
func GetPids(dir string) ([]int, error) {
339-
return readProcsFile(filepath.Join(dir, CgroupProcesses))
339+
return readProcsFile(dir)
340340
}
341341

342342
// WriteCgroupProc writes the specified pid into the cgroup's cgroup.procs file

0 commit comments

Comments
 (0)