Skip to content

Commit 352c8d4

Browse files
authored
Merge pull request #4636 from lifubang/fix-exec-timens
libct: don't send config to nsexec when joining an existing timens
2 parents cfb643e + ad09197 commit 352c8d4

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

libcontainer/container_linux.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,8 +1146,9 @@ func (c *Container) bootstrapData(cloneFlags uintptr, nsMaps map[configs.Namespa
11461146
Value: c.config.RootlessEUID,
11471147
})
11481148

1149-
// write boottime and monotonic time ns offsets.
1150-
if c.config.TimeOffsets != nil {
1149+
// write boottime and monotonic time ns offsets only when we are not joining an existing time ns
1150+
_, joinExistingTime := nsMaps[configs.NEWTIME]
1151+
if !joinExistingTime && c.config.TimeOffsets != nil {
11511152
var offsetSpec bytes.Buffer
11521153
for clock, offset := range c.config.TimeOffsets {
11531154
fmt.Fprintf(&offsetSpec, "%s %d %d\n", clock, offset.Secs, offset.Nanosecs)

tests/integration/timens.bats

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,26 @@ function teardown() {
5454
grep -E '^boottime\s+1337\s+3141519$' <<<"$output"
5555
}
5656

57+
# https://github.com/opencontainers/runc/issues/4635
58+
@test "runc exec [simple timens]" {
59+
requires timens
60+
61+
update_config '.process.args = ["sleep", "inf"]'
62+
update_config '.linux.namespaces += [{"type": "time"}]
63+
| .linux.timeOffsets = {
64+
"monotonic": { "secs": 7881, "nanosecs": 2718281 },
65+
"boottime": { "secs": 1337, "nanosecs": 3141519 }
66+
}'
67+
68+
runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox
69+
[ "$status" -eq 0 ]
70+
71+
runc exec test_busybox cat /proc/self/timens_offsets
72+
[ "$status" -eq 0 ]
73+
grep -E '^monotonic\s+7881\s+2718281$' <<<"$output"
74+
grep -E '^boottime\s+1337\s+3141519$' <<<"$output"
75+
}
76+
5777
@test "runc run [simple timens + userns]" {
5878
requires root
5979
requires timens

0 commit comments

Comments
 (0)