added version detecting

This commit is contained in:
Nicholas Orlowsky 2023-03-31 00:36:12 -05:00
parent e4a11295ab
commit 221e85f6f2
No known key found for this signature in database
GPG key ID: 58832FD3AC16C706

View file

@ -62,8 +62,12 @@ func NumCPU() int {
} }
func getCgroupVersion() int64 { func getCgroupVersion() int64 {
// TODO: detect version // /sys/fs/cgroup/cgroup.controllers will not exist with cgroupsv1
return 2; if _, err := os.Stat("/sys/fs/cgroup/cgroup.controllers"); err == nil {
return 2;
} else {
return 1;
}
} }
func readCgroup2FileToInt64Tuple(cgroupPath, cgroupFile string) (int64, int64) { func readCgroup2FileToInt64Tuple(cgroupPath, cgroupFile string) (int64, int64) {
@ -75,6 +79,7 @@ func readCgroup2FileToInt64Tuple(cgroupPath, cgroupFile string) (int64, int64) {
// file contents looks like: $MAX $PERIOD // file contents looks like: $MAX $PERIOD
// $MAX can have value "max" indicating no limit // $MAX can have value "max" indicating no limit
// it is possible for $PERIOD to be unset
values := strings.Fields(string(contents)); values := strings.Fields(string(contents));