2021-08-23 09:14:53 -04:00
|
|
|
//go:build !windows
|
2016-12-16 09:13:23 -05:00
|
|
|
// +build !windows
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
2021-08-24 06:10:50 -04:00
|
|
|
"os"
|
2016-12-16 09:13:23 -05:00
|
|
|
"os/exec"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/docker/docker/pkg/sysinfo"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
// SysInfo stores information about which features a kernel supports.
|
|
|
|
SysInfo *sysinfo.SysInfo
|
|
|
|
)
|
|
|
|
|
|
|
|
func cpuCfsPeriod() bool {
|
2017-09-11 10:23:59 -04:00
|
|
|
return testEnv.DaemonInfo.CPUCfsPeriod
|
2016-12-16 09:13:23 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func cpuCfsQuota() bool {
|
2017-09-11 10:23:59 -04:00
|
|
|
return testEnv.DaemonInfo.CPUCfsQuota
|
2016-12-16 09:13:23 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func cpuShare() bool {
|
2017-09-11 10:23:59 -04:00
|
|
|
return testEnv.DaemonInfo.CPUShares
|
2016-12-16 09:13:23 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func oomControl() bool {
|
2017-09-11 10:23:59 -04:00
|
|
|
return testEnv.DaemonInfo.OomKillDisable
|
2016-12-16 09:13:23 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func pidsLimit() bool {
|
|
|
|
return SysInfo.PidsLimit
|
|
|
|
}
|
|
|
|
|
|
|
|
func memoryLimitSupport() bool {
|
2017-09-11 10:23:59 -04:00
|
|
|
return testEnv.DaemonInfo.MemoryLimit
|
2016-12-16 09:13:23 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func memoryReservationSupport() bool {
|
|
|
|
return SysInfo.MemoryReservation
|
|
|
|
}
|
|
|
|
|
|
|
|
func swapMemorySupport() bool {
|
2017-09-11 10:23:59 -04:00
|
|
|
return testEnv.DaemonInfo.SwapLimit
|
2016-12-16 09:13:23 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func memorySwappinessSupport() bool {
|
2018-12-24 07:25:53 -05:00
|
|
|
return testEnv.IsLocalDaemon() && SysInfo.MemorySwappiness
|
2016-12-16 09:13:23 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func blkioWeight() bool {
|
2018-12-24 07:25:53 -05:00
|
|
|
return testEnv.IsLocalDaemon() && SysInfo.BlkioWeight
|
2016-12-16 09:13:23 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func cgroupCpuset() bool {
|
2017-09-11 10:23:59 -04:00
|
|
|
return testEnv.DaemonInfo.CPUSet
|
2016-12-16 09:13:23 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func seccompEnabled() bool {
|
|
|
|
return supportsSeccomp && SysInfo.Seccomp
|
|
|
|
}
|
|
|
|
|
|
|
|
func bridgeNfIptables() bool {
|
|
|
|
return !SysInfo.BridgeNFCallIPTablesDisabled
|
|
|
|
}
|
|
|
|
|
|
|
|
func unprivilegedUsernsClone() bool {
|
2021-08-24 06:10:50 -04:00
|
|
|
content, err := os.ReadFile("/proc/sys/kernel/unprivileged_userns_clone")
|
2016-12-16 09:13:23 -05:00
|
|
|
return err != nil || !strings.Contains(string(content), "0")
|
|
|
|
}
|
|
|
|
|
|
|
|
func overlayFSSupported() bool {
|
|
|
|
cmd := exec.Command(dockerBinary, "run", "--rm", "busybox", "/bin/sh", "-c", "cat /proc/filesystems")
|
|
|
|
out, err := cmd.CombinedOutput()
|
|
|
|
if err != nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return bytes.Contains(out, []byte("overlay\n"))
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
2018-12-24 07:25:53 -05:00
|
|
|
if testEnv.IsLocalDaemon() {
|
2021-07-14 10:45:02 -04:00
|
|
|
SysInfo = sysinfo.New()
|
2017-09-11 10:23:59 -04:00
|
|
|
}
|
2016-12-16 09:13:23 -05:00
|
|
|
}
|