Browse Source

Check threads exist before trying to cancel or join them

master
Con Kolivas 10 years ago
parent
commit
dd13d356c2
  1. 8
      src/ckpool.c

8
src/ckpool.c

@ -871,8 +871,10 @@ static void __shutdown_children(ckpool_t *ckp, int sig)
{
int i;
if (ckp->pth_watchdog) {
pthread_cancel(ckp->pth_watchdog);
join_pthread(ckp->pth_watchdog);
}
for (i = 0; i < ckp->proc_instances; i++) {
pid_t pid = ckp->children[i]->pid;
@ -883,8 +885,10 @@ static void __shutdown_children(ckpool_t *ckp, int sig)
static void shutdown_children(ckpool_t *ckp, int sig)
{
if (ckp->pth_watchdog) {
pthread_cancel(ckp->pth_watchdog);
join_pthread(ckp->pth_watchdog);
}
__shutdown_children(ckp, sig);
}
@ -895,13 +899,16 @@ static void sighandler(int sig)
LOGWARNING("Parent process %s received signal %d, shutting down",
ckp->name, sig);
if (ckp->pth_watchdog) {
pthread_cancel(ckp->pth_watchdog);
join_pthread(ckp->pth_watchdog);
}
__shutdown_children(ckp, SIGTERM);
/* Wait a second, then send SIGKILL */
sleep(1);
__shutdown_children(ckp, SIGKILL);
if (ckp->pth_listener)
pthread_cancel(ckp->pth_listener);
exit(0);
}
@ -1310,6 +1317,7 @@ int main(int argc, char **argv)
sigaction(SIGINT, &handler, NULL);
/* Shutdown from here if the listener is sent a shutdown message */
if (ckp.pth_listener)
join_pthread(ckp.pth_listener);
shutdown_children(&ckp, SIGTERM);

Loading…
Cancel
Save