Skip to content

Commit

Permalink
pkg:cgroups: fix parsing process cgroups for cgroupv1
Browse files Browse the repository at this point in the history
The CgroupIDFromPID() function parses the process cgroup hierarchies
obtained from /proc/pid/cgroup , it was not tested on cgroupv1 however
it contains a bug, let's fix this. We want the cgroup hierarchy ID
since that's the one that is exposed by the kernel not the cgroup
subsystem index which is used in bpf to read cgroupv1 css indexes.

Signed-off-by: Djalal Harouni <[email protected]>
  • Loading branch information
tixxdz committed Oct 30, 2024
1 parent dfaf03d commit ae10919
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions pkg/cgroups/cgroups.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,8 @@ func setCgrpv1SubsystemIdx(controller *CgroupController) {
}

// GetCgrpHierarchyID() returns the ID of the Cgroup hierarchy
// that is used to track processes. This is used for Cgroupv1 as for
// Cgroupv2 we run in the default hierarchy.
// that is used to track processes. This is used mostly for
// Cgroupv1 as for Cgroupv2 we run in the default hierarchy.
func GetCgrpHierarchyID() uint32 {
return cgrpHierarchy
}
Expand Down Expand Up @@ -807,7 +807,7 @@ func CgroupIDFromPID(pid uint32) (uint64, error) {
case CGROUP_LEGACY, CGROUP_HYBRID:
pathFunc = func(line string) (bool, string) {
// TODO: test the cgroup v1 implementation
v1Prefix := fmt.Sprintf("%d:%s:", GetCgrpv1SubsystemIdx(), GetCgrpControllerName())
v1Prefix := fmt.Sprintf("%d:%s:", GetCgrpHierarchyID(), GetCgrpControllerName())
if !strings.HasPrefix(line, v1Prefix) {
return false, ""
}
Expand Down

0 comments on commit ae10919

Please sign in to comment.