mirror of
https://github.com/moby/moby.git
synced 2026-06-24 08:48:23 +00:00
pkg/sysinfo: add detection for time-namespaces support
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
@@ -26,6 +26,7 @@ func newV2(options ...Opt) *SysInfo {
|
||||
applyAppArmorInfo,
|
||||
applySeccompInfo,
|
||||
applyCgroupNsInfo,
|
||||
applyTimeNsInfo,
|
||||
}
|
||||
|
||||
m, err := cgroupsV2.Load(sysInfo.cg2GroupPath)
|
||||
|
||||
@@ -21,6 +21,9 @@ type SysInfo struct {
|
||||
// Whether the kernel supports cgroup namespaces or not
|
||||
CgroupNamespaces bool
|
||||
|
||||
// TimeNamespaces indicates whether the kernel supports time namespaces.
|
||||
TimeNamespaces bool
|
||||
|
||||
// Whether IPv4 forwarding is supported or not, if this was disabled, networking will not work
|
||||
IPv4ForwardingDisabled bool
|
||||
|
||||
|
||||
@@ -105,6 +105,7 @@ func newV1() *SysInfo {
|
||||
applyAppArmorInfo,
|
||||
applySeccompInfo,
|
||||
applyCgroupNsInfo,
|
||||
applyTimeNsInfo,
|
||||
}
|
||||
|
||||
sysInfo.cgMounts, err = findCgroupV1Mountpoints()
|
||||
@@ -283,6 +284,11 @@ func applyCgroupNsInfo(info *SysInfo) {
|
||||
info.CgroupNamespaces = cgroupnsSupported()
|
||||
}
|
||||
|
||||
// applyTimeNsInfo adds whether time namespaces are supported to the info.
|
||||
func applyTimeNsInfo(info *SysInfo) {
|
||||
info.TimeNamespaces = timeNsSupported()
|
||||
}
|
||||
|
||||
// applySeccompInfo checks if Seccomp is supported, via CONFIG_SECCOMP.
|
||||
func applySeccompInfo(info *SysInfo) {
|
||||
info.Seccomp = seccomp.IsEnabled()
|
||||
@@ -306,6 +312,14 @@ func cgroupnsSupported() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// timeNsSupported checks whether time namespaces are supported.
|
||||
func timeNsSupported() bool {
|
||||
if _, err := os.Stat("/proc/self/ns/time"); !os.IsNotExist(err) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func cgroupEnabled(mountPoint, name string) bool {
|
||||
_, err := os.Stat(path.Join(mountPoint, name))
|
||||
return err == nil
|
||||
|
||||
@@ -64,6 +64,9 @@ func TestNew(t *testing.T) {
|
||||
if expected := cgroupnsSupported(); sysInfo.CgroupNamespaces != expected {
|
||||
t.Errorf("got CgroupNamespaces %v, wanted %v", sysInfo.CgroupNamespaces, expected)
|
||||
}
|
||||
if expected := timeNsSupported(); sysInfo.TimeNamespaces != expected {
|
||||
t.Errorf("got TimeNamespaces %v, wanted %v", sysInfo.TimeNamespaces, expected)
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsCpusetListAvailable(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user