mirror of
https://github.com/torvalds/linux.git
synced 2026-07-28 01:55:51 +02:00
selftests/namespaces: Kill grandchild in nsid fixture teardown
The timens_separate and pidns_separate test cases fork a grandchild that calls pause(). FIXTURE_TEARDOWN only kills the direct child, which is the init process of the grandchild's namespace. Once the child (init) exits, the grandchild is reparented to the host init but remains alive and continues to hold the inherited write end of the test runner's TAP pipe open. tap_prefix never receives EOF and blocks indefinitely, hanging the entire test collection. Record the grandchild PID in the fixture struct so that teardown can send SIGKILL and reap it before dealing with the child. The grandchild must be reaped first because the child acts as its PID namespace init; killing the child first would kill the grandchild without giving us a chance to waitpid() it. Signed-off-by: Ricardo B. Marlière <rbm@suse.com> Link: https://patch.msgid.link/20260407-selftests-namespaces_fixes-v1-1-59109909d88b@suse.com Signed-off-by: Christian Brauner <brauner@kernel.org>
This commit is contained in:
parent
6f43b87876
commit
fdb48976b6
|
|
@ -25,14 +25,24 @@
|
|||
/* Fixture for tests that create child processes */
|
||||
FIXTURE(nsid) {
|
||||
pid_t child_pid;
|
||||
pid_t grandchild_pid;
|
||||
};
|
||||
|
||||
FIXTURE_SETUP(nsid) {
|
||||
self->child_pid = 0;
|
||||
self->grandchild_pid = 0;
|
||||
}
|
||||
|
||||
FIXTURE_TEARDOWN(nsid) {
|
||||
/* Clean up any child process that may still be running */
|
||||
/*
|
||||
* Kill grandchild first: timens_separate and pidns_separate fork a
|
||||
* grandchild that calls pause(). It is reparented to init on child
|
||||
* exit and keeps the test runner's tap pipe open, hanging the runner.
|
||||
*/
|
||||
if (self->grandchild_pid > 0) {
|
||||
kill(self->grandchild_pid, SIGKILL);
|
||||
waitpid(self->grandchild_pid, NULL, 0);
|
||||
}
|
||||
if (self->child_pid > 0) {
|
||||
kill(self->child_pid, SIGKILL);
|
||||
waitpid(self->child_pid, NULL, 0);
|
||||
|
|
@ -676,6 +686,7 @@ TEST_F(nsid, timens_separate)
|
|||
|
||||
pid_t grandchild_pid;
|
||||
ASSERT_EQ(read(pipefd[0], &grandchild_pid, sizeof(grandchild_pid)), sizeof(grandchild_pid));
|
||||
self->grandchild_pid = grandchild_pid;
|
||||
close(pipefd[0]);
|
||||
|
||||
/* Open grandchild's time namespace */
|
||||
|
|
@ -797,6 +808,7 @@ TEST_F(nsid, pidns_separate)
|
|||
|
||||
pid_t grandchild_pid;
|
||||
ASSERT_EQ(read(pipefd[0], &grandchild_pid, sizeof(grandchild_pid)), sizeof(grandchild_pid));
|
||||
self->grandchild_pid = grandchild_pid;
|
||||
close(pipefd[0]);
|
||||
|
||||
/* Open grandchild's PID namespace */
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user