Without this patch, when killing the master process, the SIGTERM
signal is forwarded to all children. Last children will likely exit
with "killed by signal SIGTERM" status which would be converted by an
exit with status 143 of the master process.
With this patch, the master process takes note it is requesting its
children to stop and will convert "killed by signal SIGTERM" to an
exit status of 0. Therefore, the master process will exit with status
0 if everything happens as expected.
Killing a worker process with SIGTERM will still trigger an exit of
the master process with a status of 143.
---
src/haproxy.c | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/src/haproxy.c b/src/haproxy.c
index 11d1d47ceb41..2f11ad124873 100644
--- a/src/haproxy.c
+++ b/src/haproxy.c
@@ -723,6 +723,7 @@ static void mworker_wait()
{
int exitpid = -1;
int status = 0;
+ int exiting = 0;
restart_wait:
@@ -749,6 +750,7 @@ restart_wait:
}
#endif
ha_warning("Exiting Master process...\n");
+ exiting = 1;
mworker_kill(sig);
mworker_unregister_signals();
}
@@ -763,8 +765,13 @@ restart_wait:
if (WIFEXITED(status))
status = WEXITSTATUS(status);
- else if (WIFSIGNALED(status))
- status = 128 + WTERMSIG(status);
+ else if (WIFSIGNALED(status)) {
+ if (exiting && (WTERMSIG(status) == SIGINT ||
+ WTERMSIG(status) == SIGTERM))
+ status = 0;
+ else
+ status = 128 + WTERMSIG(status);
+ }
else if (WIFSTOPPED(status))
status = 128 + WSTOPSIG(status);
else
@@ -776,7 +783,7 @@ restart_wait:
/* check if exited child was in the current children
list */
if (current_child(exitpid)) {
ha_alert("Current worker %d exited with code
%d\n", exitpid, status);
- if (status != 0 && status != 130 && status !=
143
+ if (status != 0
&& !(global.tune.options &
GTUNE_NOEXIT_ONFAILURE)) {
ha_alert("exit-on-failure: killing
every workers with SIGTERM\n");
mworker_kill(SIGTERM);
--
2.18.0