Skip to content

Commit

Permalink
Merge pull request #179 from coroot/fix_cgroup2_path
Browse files Browse the repository at this point in the history
enhance accuracy of cgroup2 base path detection
  • Loading branch information
def authored Feb 14, 2025
2 parents 2e749e9 + 1260e7f commit 5306dcd
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion cgroup/cgroup_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"os"
"path"
"runtime"
"strings"

"github.com/vishvananda/netns"
"golang.org/x/sys/unix"
Expand Down Expand Up @@ -38,7 +39,14 @@ func Init() error {
}
}
if _, err := os.Stat(path.Join(cgRoot, "unified")); err == nil {
cg2Root = path.Join(cgRoot, "unified")
if data, err := os.ReadFile("/proc/self/mounts"); err == nil {
for _, line := range strings.Split(string(data), "\n") {
if strings.Contains(line, "cgroup/unified") {
cg2Root = path.Join(cgRoot, "unified")
break
}
}
}
}
klog.Infoln("cgroup v2 root is", cg2Root)
return nil
Expand Down

0 comments on commit 5306dcd

Please sign in to comment.