Skip to content

Commit

Permalink
Merge pull request #89 from giuseppe/pids-cleanup
Browse files Browse the repository at this point in the history
pids: some cleanups
  • Loading branch information
rhatdan authored Sep 21, 2021
2 parents 80d58b2 + e97e8c7 commit b2c8a53
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions internal/proc/pids.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func GetPIDs() ([]string, error) {
return pids, nil
}

// GetPIDsFromCgroup returns a strings slice of all pids listesd in pid's pids
// GetPIDsFromCgroup returns a strings slice of all pids listed in pid's pids
// cgroup. It automatically detects if we're running in unified mode or not.
func GetPIDsFromCgroup(pid string) ([]string, error) {
unified, err := cgroups.IsCgroup2UnifiedMode()
Expand All @@ -65,7 +65,7 @@ func GetPIDsFromCgroup(pid string) ([]string, error) {
return getPIDsFromCgroupV1(pid)
}

// getPIDsFromCgroupV1 returns a strings slice of all pids listesd in pid's pids
// getPIDsFromCgroupV1 returns a strings slice of all pids listed in pid's pids
// cgroup.
func getPIDsFromCgroupV1(pid string) ([]string, error) {
// First, find the corresponding path to the PID cgroup.
Expand All @@ -83,7 +83,8 @@ func getPIDsFromCgroupV1(pid string) ([]string, error) {
continue
}
if fields[1] == "pids" {
cgroupPath = fmt.Sprintf("/sys/fs/cgroup/pids/%s/cgroup.procs", fields[2])
cgroupPath = filepath.Join(cgroups.CgroupRoot, "pids", fields[2], "cgroup.procs")
break
}
}

Expand All @@ -107,7 +108,7 @@ func getPIDsFromCgroupV1(pid string) ([]string, error) {
return pids, nil
}

// getPIDsFromCgroupV2 returns a strings slice of all pids listesd in pid's pids
// getPIDsFromCgroupV2 returns a strings slice of all pids listed in pid's pids
// cgroup.
func getPIDsFromCgroupV2(pid string) ([]string, error) {
// First, find the corresponding path to the PID cgroup.
Expand All @@ -124,8 +125,10 @@ func getPIDsFromCgroupV2(pid string) ([]string, error) {
if len(fields) != 3 {
continue
}
cgroupSlice = fields[2]
break
if fields[1] == "" {
cgroupSlice = fields[2]
break
}
}

if cgroupSlice == "" {
Expand Down

0 comments on commit b2c8a53

Please sign in to comment.