Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libcontainer/cgroups/fs/apply_raw.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ func (m *Manager) GetPids() ([]int, error) {
return nil, err
}

return cgroups.ReadProcsFile(dir)
return cgroups.GetPids(dir)
}

func getCgroupData(c *configs.Cgroup, pid int) (*data, error) {
Expand Down
5 changes: 2 additions & 3 deletions libcontainer/cgroups/systemd/apply_systemd.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,12 +411,11 @@ func (m *Manager) Freeze(state configs.FreezerState) error {
}

func (m *Manager) GetPids() ([]int, error) {
path, err := getSubsystemPath(m.Cgroups, "cpu")
path, err := getSubsystemPath(m.Cgroups, "devices")
if err != nil {
return nil, err
}

return cgroups.ReadProcsFile(path)
return cgroups.GetPids(path)
}

func (m *Manager) GetStats() (*cgroups.Stats, error) {
Expand Down
28 changes: 27 additions & 1 deletion libcontainer/cgroups/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func GetInitCgroupDir(subsystem string) (string, error) {
return getControllerPath(subsystem, cgroups)
}

func ReadProcsFile(dir string) ([]int, error) {
func readProcsFile(dir string) ([]int, error) {
f, err := os.Open(filepath.Join(dir, "cgroup.procs"))
if err != nil {
return nil, err
Expand Down Expand Up @@ -322,3 +322,29 @@ func GetHugePageSize() ([]string, error) {

return pageSizes, nil
}

// GetPids returns all pids, that were added to cgroup at path and to all its
// subcgroups.
func GetPids(path string) ([]int, error) {
var pids []int
// collect pids from all sub-cgroups
err := filepath.Walk(path, func(p string, info os.FileInfo, iErr error) error {
if info.IsDir() {
return nil
}

dir, file := filepath.Split(p)
if file == "cgroup.procs" {
if iErr != nil {
return iErr
}
cPids, err := readProcsFile(dir)
if err != nil {
return err
}
pids = append(pids, cPids...)
}
return nil
})
return pids, err
}