From: Valentine Krasnobaeva Date: Fri, 22 Nov 2024 22:07:00 +0000 (+0100) Subject: REORG: startup: move mworker_prepare_master in mworker.c X-Git-Tag: v3.1.0~18 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7974089ac6f7f7548972e4e5fb2b6693773c882a;p=thirdparty%2Fhaproxy.git REORG: startup: move mworker_prepare_master in mworker.c mworker_prepare_master() performs some preparation routines for the new worker process, which will be forked during the startup. It's called only in master-worker mode, so let's move it in mworker.c. --- diff --git a/include/haproxy/mworker.h b/include/haproxy/mworker.h index 7d2fa251e6..f2c60a333d 100644 --- a/include/haproxy/mworker.h +++ b/include/haproxy/mworker.h @@ -51,4 +51,6 @@ void mworker_cleanup_proc(); void mworker_create_master_cli(void); +void mworker_prepare_master(void); + #endif /* _HAPROXY_MWORKER_H_ */ diff --git a/src/haproxy.c b/src/haproxy.c index a2dda006e3..f8d987ff21 100644 --- a/src/haproxy.c +++ b/src/haproxy.c @@ -1960,50 +1960,6 @@ static void generate_random_cluster_secret() cluster_secret_isset = 1; } -/* This function fills proc_list for master-worker mode and creates a sockpair, - * copied after master-worker fork() to each process context to enable master - * CLI at worker side (worker can send its status to master).It only returns if - * everything is OK. If something fails, it exits. - */ -static void mworker_prepare_master() -{ - struct mworker_proc *tmproc; - - setenv("HAPROXY_MWORKER", "1", 1); - - if (getenv("HAPROXY_MWORKER_REEXEC") == NULL) { - - tmproc = mworker_proc_new(); - if (!tmproc) { - ha_alert("Cannot allocate process structures.\n"); - exit(EXIT_FAILURE); - } - tmproc->options |= PROC_O_TYPE_MASTER; /* master */ - tmproc->pid = pid; - tmproc->timestamp = start_date.tv_sec; - proc_self = tmproc; - - LIST_APPEND(&proc_list, &tmproc->list); - } - - tmproc = mworker_proc_new(); - if (!tmproc) { - ha_alert("Cannot allocate process structures.\n"); - exit(EXIT_FAILURE); - } - /* worker */ - tmproc->options |= (PROC_O_TYPE_WORKER | PROC_O_INIT); - - /* create a sockpair to copy it via fork(), thus it will be in - * master and in worker processes - */ - if (socketpair(AF_UNIX, SOCK_STREAM, 0, tmproc->ipc_fd) < 0) { - ha_alert("Cannot create worker master CLI socketpair.\n"); - exit(EXIT_FAILURE); - } - LIST_APPEND(&proc_list, &tmproc->list); -} - static void mworker_run_master() { struct mworker_proc *child, *it; diff --git a/src/mworker.c b/src/mworker.c index ebe032efd1..8fd0c02a6c 100644 --- a/src/mworker.c +++ b/src/mworker.c @@ -944,6 +944,50 @@ void mworker_create_master_cli(void) } } +/* This function fills proc_list for master-worker mode and creates a sockpair, + * copied after master-worker fork() to each process context to enable master + * CLI at worker side (worker can send its status to master).It only returns if + * everything is OK. If something fails, it exits. + */ +void mworker_prepare_master(void) +{ + struct mworker_proc *tmproc; + + setenv("HAPROXY_MWORKER", "1", 1); + + if (getenv("HAPROXY_MWORKER_REEXEC") == NULL) { + + tmproc = mworker_proc_new(); + if (!tmproc) { + ha_alert("Cannot allocate process structures.\n"); + exit(EXIT_FAILURE); + } + tmproc->options |= PROC_O_TYPE_MASTER; /* master */ + tmproc->pid = pid; + tmproc->timestamp = start_date.tv_sec; + proc_self = tmproc; + + LIST_APPEND(&proc_list, &tmproc->list); + } + + tmproc = mworker_proc_new(); + if (!tmproc) { + ha_alert("Cannot allocate process structures.\n"); + exit(EXIT_FAILURE); + } + /* worker */ + tmproc->options |= (PROC_O_TYPE_WORKER | PROC_O_INIT); + + /* create a sockpair to copy it via fork(), thus it will be in + * master and in worker processes + */ + if (socketpair(AF_UNIX, SOCK_STREAM, 0, tmproc->ipc_fd) < 0) { + ha_alert("Cannot create worker master CLI socketpair.\n"); + exit(EXIT_FAILURE); + } + LIST_APPEND(&proc_list, &tmproc->list); +} + static struct cfg_kw_list mworker_kws = {{ }, { { CFG_GLOBAL, "mworker-max-reloads", mworker_parse_global_max_reloads, KWF_DISCOVERY }, { 0, NULL, NULL },