diff --git a/sysinfo/sysinfo.go b/sysinfo/sysinfo.go index 3adaa94..cbd0099 100644 --- a/sysinfo/sysinfo.go +++ b/sysinfo/sysinfo.go @@ -14,6 +14,7 @@ type SysInfo struct { cgroupCPUInfo cgroupBlkioInfo cgroupCpusetInfo + cgroupPids // Whether IPv4 forwarding is supported or not, if this was disabled, networking will not work IPv4ForwardingDisabled bool @@ -90,6 +91,11 @@ type cgroupCpusetInfo struct { Mems string } +type cgroupPids struct { + // Whether Pids Limit is supported or not + PidsLimit bool +} + // IsCpusetCpusAvailable returns `true` if the provided string set is contained // in cgroup's cpuset.cpus set, `false` otherwise. // If error is not nil a parsing error occurred. diff --git a/sysinfo/sysinfo_linux.go b/sysinfo/sysinfo_linux.go index 7f584bb..41fb0d2 100644 --- a/sysinfo/sysinfo_linux.go +++ b/sysinfo/sysinfo_linux.go @@ -44,6 +44,7 @@ func New(quiet bool) *SysInfo { sysInfo.cgroupCPUInfo = checkCgroupCPU(cgMounts, quiet) sysInfo.cgroupBlkioInfo = checkCgroupBlkioInfo(cgMounts, quiet) sysInfo.cgroupCpusetInfo = checkCgroupCpusetInfo(cgMounts, quiet) + sysInfo.cgroupPids = checkCgroupPids(quiet) } _, ok := cgMounts["devices"] @@ -216,6 +217,21 @@ func checkCgroupCpusetInfo(cgMounts map[string]string, quiet bool) cgroupCpusetI } } +// checkCgroupPids reads the pids information from the pids cgroup mount point. +func checkCgroupPids(quiet bool) cgroupPids { + _, err := cgroups.FindCgroupMountpoint("pids") + if err != nil { + if !quiet { + logrus.Warn(err) + } + return cgroupPids{} + } + + return cgroupPids{ + PidsLimit: true, + } +} + func cgroupEnabled(mountPoint, name string) bool { _, err := os.Stat(path.Join(mountPoint, name)) return err == nil