mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2026-01-30 14:31:08 +01:00
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.
This commit is contained in:
parent
41cc1fe310
commit
7974089ac6
@ -51,4 +51,6 @@ void mworker_cleanup_proc();
|
||||
|
||||
void mworker_create_master_cli(void);
|
||||
|
||||
void mworker_prepare_master(void);
|
||||
|
||||
#endif /* _HAPROXY_MWORKER_H_ */
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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 },
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user