diff --git a/namespaces/nsenter/nsenter.c b/namespaces/nsenter/nsenter.c index 4ab21774f..747fce3a4 100644 --- a/namespaces/nsenter/nsenter.c +++ b/namespaces/nsenter/nsenter.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -84,6 +85,12 @@ void print_usage() "nsenter --nspid --console -- cmd1 arg1 arg2...\n"); } +void child_handler(int sig) +{ + while (waitpid(-1, NULL, WNOHANG) > 0) { + } +} + void nsenter() { int argc, c; @@ -102,6 +109,15 @@ void nsenter() pr_perror("Failed to set child subreaper"); exit(1); } + // setup SIGCHLD handler to reap zombie processes + struct sigaction sa; + sigemptyset(&sa.sa_mask); + sa.sa_handler = &child_handler; + sa.sa_flags = SA_RESTART | SA_NOCLDSTOP; + if (sigaction(SIGCHLD, &sa, NULL) == -1) { + pr_perror("Failed to set SIGCHLD handler"); + exit(1); + } #endif static const struct option longopts[] = {