Fix zombie grandchild processes spawned by timens_separate and
pidns_separate tests in nsid_test.c. This also prevents kselftest from
hanging up after running these tests.

Signed-off-by: Yohei Kojima <[email protected]>
---
 tools/testing/selftests/namespaces/nsid_test.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/tools/testing/selftests/namespaces/nsid_test.c 
b/tools/testing/selftests/namespaces/nsid_test.c
index b4a14c6693a5..1e2669372b7b 100644
--- a/tools/testing/selftests/namespaces/nsid_test.c
+++ b/tools/testing/selftests/namespaces/nsid_test.c
@@ -25,10 +25,12 @@
 /* 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) {
@@ -37,6 +39,10 @@ FIXTURE_TEARDOWN(nsid) {
                kill(self->child_pid, SIGKILL);
                waitpid(self->child_pid, NULL, 0);
        }
+       if (self->grandchild_pid > 0) {
+               kill(self->grandchild_pid, SIGKILL);
+               waitpid(self->grandchild_pid, NULL, 0);
+       }
 }
 
 TEST(nsid_mntns_basic)
@@ -677,6 +683,7 @@ TEST_F(nsid, timens_separate)
        pid_t grandchild_pid;
        ASSERT_EQ(read(pipefd[0], &grandchild_pid, sizeof(grandchild_pid)), 
sizeof(grandchild_pid));
        close(pipefd[0]);
+       self->grandchild_pid = grandchild_pid;
 
        /* Open grandchild's time namespace */
        char path[256];
@@ -798,6 +805,7 @@ TEST_F(nsid, pidns_separate)
        pid_t grandchild_pid;
        ASSERT_EQ(read(pipefd[0], &grandchild_pid, sizeof(grandchild_pid)), 
sizeof(grandchild_pid));
        close(pipefd[0]);
+       self->grandchild_pid = grandchild_pid;
 
        /* Open grandchild's PID namespace */
        char path[256];
-- 
2.52.0


Reply via email to