From badfb12da29db09c62e497378a2ce0ac74499031 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Thu, 12 Jun 2014 22:14:52 +1000 Subject: [PATCH] Do not try to send messages from the main signal handler to the children processes since they'll detect main disappearing and do not try to pthread join a dead thread --- src/ckpool.c | 17 +++++++---------- src/libckpool.c | 3 ++- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/ckpool.c b/src/ckpool.c index 7898037a..fd055110 100644 --- a/src/ckpool.c +++ b/src/ckpool.c @@ -550,25 +550,22 @@ static void shutdown_children(ckpool_t *ckp, int sig) static void sighandler(int sig) { - int i; - - pthread_cancel(global_ckp->pth_watchdog); - join_pthread(global_ckp->pth_watchdog); + ckpool_t *ckp = global_ckp; - for (i = 0; i < global_ckp->proc_instances; i++) - send_proc(global_ckp->children[i], "shutdown"); + pthread_cancel(ckp->pth_watchdog); + join_pthread(ckp->pth_watchdog); if (sig != 9) { /* Wait a second, then send SIGTERM */ sleep(1); - __shutdown_children(global_ckp, SIGTERM); + __shutdown_children(ckp, SIGTERM); /* Wait another second, then send SIGKILL */ sleep(1); - __shutdown_children(global_ckp, SIGKILL); - pthread_cancel(global_ckp->pth_listener); + __shutdown_children(ckp, SIGKILL); + pthread_cancel(ckp->pth_listener); exit(0); } else { - __shutdown_children(global_ckp, SIGKILL); + __shutdown_children(ckp, SIGKILL); exit(1); } } diff --git a/src/libckpool.c b/src/libckpool.c index d9efa7b9..aada784a 100644 --- a/src/libckpool.c +++ b/src/libckpool.c @@ -71,7 +71,8 @@ void create_pthread(pthread_t *thread, void *(*start_routine)(void *), void *arg void join_pthread(pthread_t thread) { - pthread_join(thread, NULL); + if (!pthread_kill(thread, 0)) + pthread_join(thread, NULL); }