Skip to content
This repository was archived by the owner on Dec 13, 2018. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions namespaces/nsenter/nsenter.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <string.h>
#include <sys/prctl.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <getopt.h>

Expand Down Expand Up @@ -84,6 +85,12 @@ void print_usage()
"nsenter --nspid <pid> --console <console> -- cmd1 arg1 arg2...\n");
}

void child_handler(int sig)
{
while (waitpid(-1, NULL, WNOHANG) > 0) {
}
}

void nsenter()
{
int argc, c;
Expand All @@ -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[] = {
Expand Down