# HG changeset patch # User jbe # Date 1434751331 -7200 # Node ID 05fd82e3cfb757411b8e0cda07be01bcd985ee5f # Parent 822ccaeccccbccd0cd00219759c5986f3251726b Send SIGUSR1 to all child processes on termination via SIGTERM diff -r 822ccaeccccb -r 05fd82e3cfb7 moonbridge.c --- a/moonbridge.c Sat Jun 20 00:00:32 2015 +0200 +++ b/moonbridge.c Sat Jun 20 00:02:11 2015 +0200 @@ -338,6 +338,7 @@ signal(SIGINT, moonbr_signal); signal(SIGTERM, moonbr_signal); signal(SIGCHLD, moonbr_signal); + signal(SIGUSR1, moonbr_signal); } @@ -1145,6 +1146,13 @@ } } moonbr_poll_shutdown(); /* avoids loops due to error condition when polling closed listeners */ + { + pid_t pgrp = getpgrp(); + moonbr_log(LOG_INFO, "Sending SIGUSR1 to all processes in group %i", (int)pgrp); + if (killpg(pgrp, SIGUSR1)) { + moonbr_log(LOG_WARNING, "Error while sending SIGUSR1 to own process group: %s", strerror(errno)); + } + } } @@ -1681,15 +1689,14 @@ } /* terminate idle workers in case of shutdown and check if shutdown is complete */ if (moonbr_shutdown_in_progress) { + int remaining = 0; for (pool=moonbr_first_pool; pool; pool=pool->next_pool) { - if (pool->first_worker) { - while (pool->idle_worker_count) { - moonbr_terminate_idle_worker(moonbr_pop_idle_worker(pool)); - } - break; + while (pool->idle_worker_count) { + moonbr_terminate_idle_worker(moonbr_pop_idle_worker(pool)); } + if (pool->first_worker) remaining = 1; } - if (!pool) { + if (!remaining) { moonbr_log(LOG_INFO, "All worker threads have terminated"); moonbr_terminate(MOONBR_EXITCODE_GRACEFUL); }