Browse code

pkg/sysinfo: add detection for time-namespaces support

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

Sebastiaan van Stijn authored on 2026/04/07 05:37:18
Showing 4 changed files
... ...
@@ -26,6 +26,7 @@ func newV2(options ...Opt) *SysInfo {
26 26
 		applyAppArmorInfo,
27 27
 		applySeccompInfo,
28 28
 		applyCgroupNsInfo,
29
+		applyTimeNsInfo,
29 30
 	}
30 31
 
31 32
 	m, err := cgroupsV2.Load(sysInfo.cg2GroupPath)
... ...
@@ -21,6 +21,9 @@ type SysInfo struct {
21 21
 	// Whether the kernel supports cgroup namespaces or not
22 22
 	CgroupNamespaces bool
23 23
 
24
+	// TimeNamespaces indicates whether the kernel supports time namespaces.
25
+	TimeNamespaces bool
26
+
24 27
 	// Whether IPv4 forwarding is supported or not, if this was disabled, networking will not work
25 28
 	IPv4ForwardingDisabled bool
26 29
 
... ...
@@ -105,6 +105,7 @@ func newV1() *SysInfo {
105 105
 		applyAppArmorInfo,
106 106
 		applySeccompInfo,
107 107
 		applyCgroupNsInfo,
108
+		applyTimeNsInfo,
108 109
 	}
109 110
 
110 111
 	sysInfo.cgMounts, err = findCgroupV1Mountpoints()
... ...
@@ -283,6 +284,11 @@ func applyCgroupNsInfo(info *SysInfo) {
283 283
 	info.CgroupNamespaces = cgroupnsSupported()
284 284
 }
285 285
 
286
+// applyTimeNsInfo adds whether time namespaces are supported to the info.
287
+func applyTimeNsInfo(info *SysInfo) {
288
+	info.TimeNamespaces = timeNsSupported()
289
+}
290
+
286 291
 // applySeccompInfo checks if Seccomp is supported, via CONFIG_SECCOMP.
287 292
 func applySeccompInfo(info *SysInfo) {
288 293
 	info.Seccomp = seccomp.IsEnabled()
... ...
@@ -306,6 +312,14 @@ func cgroupnsSupported() bool {
306 306
 	return false
307 307
 }
308 308
 
309
+// timeNsSupported checks whether time namespaces are supported.
310
+func timeNsSupported() bool {
311
+	if _, err := os.Stat("/proc/self/ns/time"); !os.IsNotExist(err) {
312
+		return true
313
+	}
314
+	return false
315
+}
316
+
309 317
 func cgroupEnabled(mountPoint, name string) bool {
310 318
 	_, err := os.Stat(path.Join(mountPoint, name))
311 319
 	return err == nil
... ...
@@ -64,6 +64,9 @@ func TestNew(t *testing.T) {
64 64
 	if expected := cgroupnsSupported(); sysInfo.CgroupNamespaces != expected {
65 65
 		t.Errorf("got CgroupNamespaces %v, wanted %v", sysInfo.CgroupNamespaces, expected)
66 66
 	}
67
+	if expected := timeNsSupported(); sysInfo.TimeNamespaces != expected {
68
+		t.Errorf("got TimeNamespaces %v, wanted %v", sysInfo.TimeNamespaces, expected)
69
+	}
67 70
 }
68 71
 
69 72
 func TestIsCpusetListAvailable(t *testing.T) {