From 78a312166869e50ea69ac377387d2e184fe1b6ec Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Thu, 1 May 2014 12:30:43 +1000 Subject: [PATCH] Add signal handlers to enable terminate requests to end cleanly allowing profile generation --- src/ckpool.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/ckpool.c b/src/ckpool.c index 10f510ad..39ee1bf2 100644 --- a/src/ckpool.c +++ b/src/ckpool.c @@ -166,6 +166,19 @@ static void shutdown_children(ckpool_t *ckp, int sig) join_pthread(ckp->pth_watchdog); kill(ckp->generator.pid, sig); kill(ckp->stratifier.pid, sig); + kill(ckp->connector.pid, sig); +} + +static void sighandler(int sig) +{ + if (sig != 9) { + shutdown_children(global_ckp, 15); + pthread_cancel(global_ckp->pth_listener); + sleep(1); + } else { + shutdown_children(global_ckp, 9); + exit(1); + } } static void json_get_string(char **store, json_t *val, const char *res) @@ -305,6 +318,7 @@ static void *watchdog(void *arg) int main(int argc, char **argv) { + struct sigaction handler; int len, c, ret; ckpool_t ckp; @@ -353,6 +367,11 @@ int main(int argc, char **argv) /* Ignore sigpipe */ signal(SIGPIPE, SIG_IGN); + handler.sa_handler = &sighandler; + handler.sa_flags = 0; + sigemptyset(&handler.sa_mask); + sigaction(SIGTERM, &handler, NULL); + sigaction(SIGINT, &handler, NULL); ret = mkdir(ckp.socket_dir, 0700); if (ret && errno != EEXIST)