Skip to content

Commit 7974089

Browse files
einval22wlallemand
authored andcommitted
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.
1 parent 41cc1fe commit 7974089

File tree

3 files changed

+46
-44
lines changed

3 files changed

+46
-44
lines changed

include/haproxy/mworker.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,6 @@ void mworker_cleanup_proc();
5151

5252
void mworker_create_master_cli(void);
5353

54+
void mworker_prepare_master(void);
55+
5456
#endif /* _HAPROXY_MWORKER_H_ */

src/haproxy.c

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1960,50 +1960,6 @@ static void generate_random_cluster_secret()
19601960
cluster_secret_isset = 1;
19611961
}
19621962

1963-
/* This function fills proc_list for master-worker mode and creates a sockpair,
1964-
* copied after master-worker fork() to each process context to enable master
1965-
* CLI at worker side (worker can send its status to master).It only returns if
1966-
* everything is OK. If something fails, it exits.
1967-
*/
1968-
static void mworker_prepare_master()
1969-
{
1970-
struct mworker_proc *tmproc;
1971-
1972-
setenv("HAPROXY_MWORKER", "1", 1);
1973-
1974-
if (getenv("HAPROXY_MWORKER_REEXEC") == NULL) {
1975-
1976-
tmproc = mworker_proc_new();
1977-
if (!tmproc) {
1978-
ha_alert("Cannot allocate process structures.\n");
1979-
exit(EXIT_FAILURE);
1980-
}
1981-
tmproc->options |= PROC_O_TYPE_MASTER; /* master */
1982-
tmproc->pid = pid;
1983-
tmproc->timestamp = start_date.tv_sec;
1984-
proc_self = tmproc;
1985-
1986-
LIST_APPEND(&proc_list, &tmproc->list);
1987-
}
1988-
1989-
tmproc = mworker_proc_new();
1990-
if (!tmproc) {
1991-
ha_alert("Cannot allocate process structures.\n");
1992-
exit(EXIT_FAILURE);
1993-
}
1994-
/* worker */
1995-
tmproc->options |= (PROC_O_TYPE_WORKER | PROC_O_INIT);
1996-
1997-
/* create a sockpair to copy it via fork(), thus it will be in
1998-
* master and in worker processes
1999-
*/
2000-
if (socketpair(AF_UNIX, SOCK_STREAM, 0, tmproc->ipc_fd) < 0) {
2001-
ha_alert("Cannot create worker master CLI socketpair.\n");
2002-
exit(EXIT_FAILURE);
2003-
}
2004-
LIST_APPEND(&proc_list, &tmproc->list);
2005-
}
2006-
20071963
static void mworker_run_master()
20081964
{
20091965
struct mworker_proc *child, *it;

src/mworker.c

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -944,6 +944,50 @@ void mworker_create_master_cli(void)
944944
}
945945
}
946946

947+
/* This function fills proc_list for master-worker mode and creates a sockpair,
948+
* copied after master-worker fork() to each process context to enable master
949+
* CLI at worker side (worker can send its status to master).It only returns if
950+
* everything is OK. If something fails, it exits.
951+
*/
952+
void mworker_prepare_master(void)
953+
{
954+
struct mworker_proc *tmproc;
955+
956+
setenv("HAPROXY_MWORKER", "1", 1);
957+
958+
if (getenv("HAPROXY_MWORKER_REEXEC") == NULL) {
959+
960+
tmproc = mworker_proc_new();
961+
if (!tmproc) {
962+
ha_alert("Cannot allocate process structures.\n");
963+
exit(EXIT_FAILURE);
964+
}
965+
tmproc->options |= PROC_O_TYPE_MASTER; /* master */
966+
tmproc->pid = pid;
967+
tmproc->timestamp = start_date.tv_sec;
968+
proc_self = tmproc;
969+
970+
LIST_APPEND(&proc_list, &tmproc->list);
971+
}
972+
973+
tmproc = mworker_proc_new();
974+
if (!tmproc) {
975+
ha_alert("Cannot allocate process structures.\n");
976+
exit(EXIT_FAILURE);
977+
}
978+
/* worker */
979+
tmproc->options |= (PROC_O_TYPE_WORKER | PROC_O_INIT);
980+
981+
/* create a sockpair to copy it via fork(), thus it will be in
982+
* master and in worker processes
983+
*/
984+
if (socketpair(AF_UNIX, SOCK_STREAM, 0, tmproc->ipc_fd) < 0) {
985+
ha_alert("Cannot create worker master CLI socketpair.\n");
986+
exit(EXIT_FAILURE);
987+
}
988+
LIST_APPEND(&proc_list, &tmproc->list);
989+
}
990+
947991
static struct cfg_kw_list mworker_kws = {{ }, {
948992
{ CFG_GLOBAL, "mworker-max-reloads", mworker_parse_global_max_reloads, KWF_DISCOVERY },
949993
{ 0, NULL, NULL },

0 commit comments

Comments
 (0)