Merge pull request #369 from dqminh/exec-reap-zombie

handle SIGCHLD when running as child subreaper
This commit is contained in:
Mrunal Patel 2015-02-10 11:11:07 -08:00
commit d6fae7bb26
1 changed files with 16 additions and 0 deletions

View File

@ -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>
@ -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;
@ -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[] = {