moonbridge
changeset 195:05fd82e3cfb7
Send SIGUSR1 to all child processes on termination via SIGTERM
author | jbe |
---|---|
date | Sat Jun 20 00:02:11 2015 +0200 (2015-06-20) |
parents | 822ccaeccccb |
children | 281f1ac41fc6 |
files | moonbridge.c |
line diff
1.1 --- a/moonbridge.c Sat Jun 20 00:00:32 2015 +0200 1.2 +++ b/moonbridge.c Sat Jun 20 00:02:11 2015 +0200 1.3 @@ -338,6 +338,7 @@ 1.4 signal(SIGINT, moonbr_signal); 1.5 signal(SIGTERM, moonbr_signal); 1.6 signal(SIGCHLD, moonbr_signal); 1.7 + signal(SIGUSR1, moonbr_signal); 1.8 } 1.9 1.10 1.11 @@ -1145,6 +1146,13 @@ 1.12 } 1.13 } 1.14 moonbr_poll_shutdown(); /* avoids loops due to error condition when polling closed listeners */ 1.15 + { 1.16 + pid_t pgrp = getpgrp(); 1.17 + moonbr_log(LOG_INFO, "Sending SIGUSR1 to all processes in group %i", (int)pgrp); 1.18 + if (killpg(pgrp, SIGUSR1)) { 1.19 + moonbr_log(LOG_WARNING, "Error while sending SIGUSR1 to own process group: %s", strerror(errno)); 1.20 + } 1.21 + } 1.22 } 1.23 1.24 1.25 @@ -1681,15 +1689,14 @@ 1.26 } 1.27 /* terminate idle workers in case of shutdown and check if shutdown is complete */ 1.28 if (moonbr_shutdown_in_progress) { 1.29 + int remaining = 0; 1.30 for (pool=moonbr_first_pool; pool; pool=pool->next_pool) { 1.31 - if (pool->first_worker) { 1.32 - while (pool->idle_worker_count) { 1.33 - moonbr_terminate_idle_worker(moonbr_pop_idle_worker(pool)); 1.34 - } 1.35 - break; 1.36 + while (pool->idle_worker_count) { 1.37 + moonbr_terminate_idle_worker(moonbr_pop_idle_worker(pool)); 1.38 } 1.39 + if (pool->first_worker) remaining = 1; 1.40 } 1.41 - if (!pool) { 1.42 + if (!remaining) { 1.43 moonbr_log(LOG_INFO, "All worker threads have terminated"); 1.44 moonbr_terminate(MOONBR_EXITCODE_GRACEFUL); 1.45 }