Skip to content

Commit d5d41de

Browse files
einval22wlallemand
authored andcommitted
MINOR: startup: replace HAPROXY_LOAD_SUCCESS with global load_status
After master-worker refactoring, master performs re-exec only once up to receiving "reload" command or USR2 signal. There is no more the second master's re-exec to free unused memory. Thus, there is no longer need to export environment variable HAPROXY_LOAD_SUCCESS with worker process load status. This status can be simply saved in a global variable load_status.
1 parent aadda34 commit d5d41de

File tree

4 files changed

+9
-12
lines changed

4 files changed

+9
-12
lines changed

include/haproxy/mworker.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <haproxy/signal-t.h>
1919

2020
extern int max_reloads;
21+
extern int load_status;
2122
extern struct mworker_proc *proc_self;
2223
/* master CLI configuration (-S flag) */
2324
extern struct list mworker_cli_conf;

src/cli.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2532,7 +2532,7 @@ static int _send_status(char **args, char *payload, struct appctx *appctx, void
25322532
kill(proc->pid, oldpids_sig);
25332533
}
25342534
}
2535-
setenv("HAPROXY_LOAD_SUCCESS", "1", 1);
2535+
load_status = 1;
25362536
ha_notice("Loading success.\n");
25372537

25382538
#if defined(USE_SYSTEMD)

src/haproxy.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -936,7 +936,7 @@ void on_new_child_failure()
936936
sock_drop_unused_old_sockets();
937937

938938
usermsgs_clr(NULL);
939-
setenv("HAPROXY_LOAD_SUCCESS", "0", 1);
939+
load_status = 0;
940940
ha_warning("Failed to load worker!\n");
941941
#if defined(USE_SYSTEMD)
942942
/* the sd_notify API is not able to send a reload failure signal. So
@@ -3048,10 +3048,10 @@ static void run_master_in_recovery_mode(int argc, char **argv)
30483048
struct mworker_proc *proc;
30493049
char *errmsg = NULL;
30503050

3051-
/* HAPROXY_LOAD_SUCCESS is checked in cli_io_handler_show_cli_sock() to
3051+
/* load_status is global and checked in cli_io_handler_show_cli_sock() to
30523052
* dump master startup logs with its alerts/warnings via master CLI sock.
30533053
*/
3054-
setenv("HAPROXY_LOAD_SUCCESS", "0", 1);
3054+
load_status = 0;
30553055

30563056
/* increment the number failed reloads */
30573057
list_for_each_entry(proc, &proc_list, list) {

src/mworker.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747

4848
static int exitcode = -1;
4949
int max_reloads = INT_MAX; /* max number of reloads a worker can have until they are killed */
50+
int load_status; /* worker process startup status: 1 - loaded successfully; 0 - load failed */
5051
struct mworker_proc *proc_self = NULL; /* process structure of current process */
5152
struct list mworker_cli_conf = LIST_HEAD_INIT(mworker_cli_conf); /* master CLI configuration (-S flag) */
5253

@@ -795,7 +796,6 @@ static int cli_parse_reload(char **args, char *payload, struct appctx *appctx, v
795796
static int cli_io_handler_show_loadstatus(struct appctx *appctx)
796797
{
797798
struct mworker_proc *proc;
798-
char *env;
799799

800800
if (!cli_has_level(appctx, ACCESS_LVL_OPER))
801801
return 1;
@@ -810,15 +810,11 @@ static int cli_io_handler_show_loadstatus(struct appctx *appctx)
810810
}
811811
}
812812

813-
env = getenv("HAPROXY_LOAD_SUCCESS");
814-
if (!env)
815-
return 1;
816-
817-
if (strcmp(env, "0") == 0) {
813+
if (load_status == 0)
818814
chunk_printf(&trash, "Success=0\n");
819-
} else if (strcmp(env, "1") == 0) {
815+
else
820816
chunk_printf(&trash, "Success=1\n");
821-
}
817+
822818
#ifdef USE_SHM_OPEN
823819
if (startup_logs && ring_data(startup_logs) > 1)
824820
chunk_appendf(&trash, "--\n");

0 commit comments

Comments
 (0)