diff --git a/tests/integration/exec.bats b/tests/integration/exec.bats index 056c53545df..11e4bb473a8 100644 --- a/tests/integration/exec.bats +++ b/tests/integration/exec.bats @@ -321,6 +321,41 @@ function check_exec_debug() { [ "$status" -eq 0 ] } +# https://github.com/opencontainers/runc/issues/5089 +@test "runc exec [init changes cgroup]" { + requires root cgroups_v2 + + NEW_CGROUP_REL=/runc-tst-$$ + NEW_CGROUP=/sys/fs/cgroup$NEW_CGROUP_REL + mkdir $NEW_CGROUP + + # The container is placed into a $CGROUP_V2_PATH cgroup. + set_cgroups_path + # And upon the start it moves itself into $NEW_CGROUP. + set_cgroup_mount_writable + update_config ' .linux.namespaces -= [{"type": "cgroup"}] + | .process.args = ["sh", "-c", "echo 1 > '$NEW_CGROUP'/cgroup.procs && exec sleep 1h"]' + + runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox + [ $status -eq 0 ] + testcontainer test_busybox running + sleep 1 + # Remove the original container cgroup. If systemd cgroup manager is used by runc, + # the cgroup might have already be deleted by systemd, so we ignore rmdir errors. + rmdir "$CGROUP_V2_PATH" || true + test -d "$CGROUP_V2_PATH" && false + + # Test that runc exec is able to fallback to container's init cgroup + # even if the original cgroup is gone. + runc exec test_busybox cat /proc/self/cgroup + [ $status -eq 0 ] + [ "$output" = "0::$NEW_CGROUP_REL" ] + + # Cleanup. + runc delete -f test_busybox + rmdir "$NEW_CGROUP" +} + @test "runc exec [execve error]" { cat <rootfs/run.sh #!/mmnnttbb foo bar