]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: mworker: exit with the incriminated exit code
authorWilliam Lallemand <wlallemand@haproxy.com>
Tue, 6 Nov 2018 16:37:14 +0000 (17:37 +0100)
committerWilly Tarreau <w@1wt.eu>
Tue, 6 Nov 2018 17:28:33 +0000 (18:28 +0100)
The former behavior was to exit() the master process with the latest
status code known, which was the one of the last process to exit.

The problem is that the master process was not exiting with the status
code which provoked the exit-on-failure.

src/haproxy.c

index 6c4fe4448c8d8a5255688fe4eb7ea52f43fd7be3..62b9d1a7841def08e30a8bcb3a1c1a6bbfa319f3 100644 (file)
@@ -193,6 +193,8 @@ static char *cur_unixsocket = NULL;
 
 int atexit_flag = 0;
 
+static int exitcode = -1;
+
 int nb_oldpids = 0;
 const int zero = 0;
 const int one = 1;
@@ -827,6 +829,8 @@ restart_wait:
                                if (status != 0 && status != 130 && status != 143
                                    && !(global.tune.options & GTUNE_NOEXIT_ONFAILURE)) {
                                        ha_alert("exit-on-failure: killing every workers with SIGTERM\n");
+                                       if (exitcode < 0)
+                                               exitcode = status;
                                        mworker_kill(SIGTERM);
                                }
                        } else {
@@ -843,6 +847,8 @@ restart_wait:
        else if (exitpid == -1 && errno == ECHILD) {
                ha_warning("All workers exited. Exiting... (%d)\n", (exitcode > 0) ? exitcode : status);
                atexit_flag = 0;
+               if (exitcode > 0)
+                       exit(exitcode);
                exit(status); /* parent must leave using the latest status code known */
        }