remsim-client: Avoid zombies when scripts terminate

This avoids the OS from keeping terminated children (scripts) around
as zombies.

Change-Id: If7d45bda160987a26c7b101db6152142dc432fe7
This commit is contained in:
Harald Welte 2020-10-20 19:14:55 +02:00
parent a5daec426e
commit dc34764648
1 changed files with 20 additions and 0 deletions

View File

@ -1,4 +1,5 @@
#include <errno.h>
#include <signal.h> #include <signal.h>
#include <unistd.h> #include <unistd.h>
#define _GNU_SOURCE #define _GNU_SOURCE
@ -142,6 +143,19 @@ static void handle_options(struct client_config *cfg, int argc, char **argv)
} }
} }
static int avoid_zombies(void)
{
static struct sigaction sa_chld;
sa_chld.sa_handler = SIG_IGN;
sigemptyset(&sa_chld.sa_mask);
sa_chld.sa_flags = SA_NOCLDWAIT;
sa_chld.sa_restorer = NULL;
return sigaction(SIGCHLD, &sa_chld, NULL);
}
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
struct bankd_client *g_client; struct bankd_client *g_client;
@ -166,6 +180,12 @@ int main(int argc, char **argv)
signal(SIGUSR1, handle_sig_usr1); signal(SIGUSR1, handle_sig_usr1);
/* Silently (and portably) reap children. */
if (avoid_zombies() < 0) {
fprintf(stderr, "Unable to silently reap children: %s\n", strerror(errno));
exit(1);
}
asn_debug = 0; asn_debug = 0;
client_user_main(g_client); client_user_main(g_client);