Skip to content

Commit 0c7b93e

Browse files
einval22wlallemand
authored andcommitted
REORG: startup: move mworker_run_master and mworker_loop in mworker.c
mworker_run_master() is called only in master mode. mworker_loop() is static and called only in mworker_run_master(). So let's move these both functions in mworker.c. We also need here to make run_thread_poll_loop() accessible from other units, as it's used in mworker_loop().
1 parent 56894db commit 0c7b93e

File tree

4 files changed

+71
-71
lines changed

4 files changed

+71
-71
lines changed

include/haproxy/global.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ int main(int argc, char **argv);
5858
void deinit(void);
5959
__attribute__((noreturn)) void deinit_and_exit(int);
6060
void run_poll_loop(void);
61+
void *run_thread_poll_loop(void *data); /* takes the thread config in argument or NULL for any thread */
6162
int tell_old_pids(int sig);
6263
int delete_oldpid(int pid);
6364
void hap_register_build_opts(const char *str, int must_free);

include/haproxy/mworker.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,6 @@ void mworker_cleanup_proc();
5252
void mworker_create_master_cli(void);
5353

5454
void mworker_prepare_master(void);
55+
void mworker_run_master(void);
5556

5657
#endif /* _HAPROXY_MWORKER_H_ */

src/haproxy.c

Lines changed: 1 addition & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,6 @@ int master = 0; /* 1 if in master, 0 if in child */
262262
/* per-boot randomness */
263263
unsigned char boot_seed[20]; /* per-boot random seed (160 bits initially) */
264264

265-
/* takes the thread config in argument or NULL for any thread */
266-
static void *run_thread_poll_loop(void *data);
267-
268265
/* bitfield of a few warnings to emit just once (WARN_*) */
269266
unsigned int warned = 0;
270267

@@ -878,42 +875,6 @@ void mworker_reload(int hardreload)
878875
mworker_reexec(hardreload);
879876
}
880877

881-
static void mworker_loop()
882-
{
883-
884-
/* Busy polling makes no sense in the master :-) */
885-
global.tune.options &= ~GTUNE_BUSY_POLLING;
886-
887-
888-
signal_unregister(SIGTTIN);
889-
signal_unregister(SIGTTOU);
890-
signal_unregister(SIGUSR1);
891-
signal_unregister(SIGHUP);
892-
signal_unregister(SIGQUIT);
893-
894-
signal_register_fct(SIGTERM, mworker_catch_sigterm, SIGTERM);
895-
signal_register_fct(SIGUSR1, mworker_catch_sigterm, SIGUSR1);
896-
signal_register_fct(SIGTTIN, mworker_broadcast_signal, SIGTTIN);
897-
signal_register_fct(SIGTTOU, mworker_broadcast_signal, SIGTTOU);
898-
signal_register_fct(SIGINT, mworker_catch_sigterm, SIGINT);
899-
signal_register_fct(SIGHUP, mworker_catch_sighup, SIGHUP);
900-
signal_register_fct(SIGUSR2, mworker_catch_sighup, SIGUSR2);
901-
signal_register_fct(SIGCHLD, mworker_catch_sigchld, SIGCHLD);
902-
903-
mworker_unblock_signals();
904-
mworker_cleantasks();
905-
906-
mworker_catch_sigchld(NULL); /* ensure we clean the children in case
907-
some SIGCHLD were lost */
908-
909-
jobs++; /* this is the "master" job, we want to take care of the
910-
signals even if there is no listener so the poll loop don't
911-
leave */
912-
913-
fork_poller();
914-
run_thread_poll_loop(NULL);
915-
}
916-
917878
/*
918879
* Exit with an error message upon a master recovery mode failure.
919880
*/
@@ -1960,37 +1921,6 @@ static void generate_random_cluster_secret()
19601921
cluster_secret_isset = 1;
19611922
}
19621923

1963-
static void mworker_run_master()
1964-
{
1965-
struct mworker_proc *child, *it;
1966-
1967-
proc_self->failedreloads = 0; /* reset the number of failure */
1968-
mworker_loop();
1969-
#if defined(USE_OPENSSL) && !defined(OPENSSL_NO_DH)
1970-
ssl_free_dh();
1971-
#endif
1972-
master = 0;
1973-
/* close useless master sockets */
1974-
mworker_cli_proxy_stop();
1975-
1976-
/* free proc struct of other processes */
1977-
list_for_each_entry_safe(child, it, &proc_list, list) {
1978-
/* close the FD of the master side for all
1979-
* workers, we don't need to close the worker
1980-
* side of other workers since it's done with
1981-
* the bind_proc */
1982-
if (child->ipc_fd[0] >= 0) {
1983-
close(child->ipc_fd[0]);
1984-
child->ipc_fd[0] = -1;
1985-
}
1986-
LIST_DELETE(&child->list);
1987-
mworker_free_child(child);
1988-
child = NULL;
1989-
}
1990-
/* master must leave */
1991-
exit(0);
1992-
}
1993-
19941924
/*
19951925
* This function does daemonization fork. It only returns if everything is OK.
19961926
* If something fails, it exits.
@@ -3405,7 +3335,7 @@ void run_poll_loop()
34053335
_HA_ATOMIC_AND(&th_ctx->flags, ~TH_FL_IN_LOOP);
34063336
}
34073337

3408-
static void *run_thread_poll_loop(void *data)
3338+
void *run_thread_poll_loop(void *data)
34093339
{
34103340
struct per_thread_alloc_fct *ptaf;
34113341
struct per_thread_init_fct *ptif;

src/mworker.c

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include <haproxy/ring.h>
3737
#include <haproxy/sc_strm.h>
3838
#include <haproxy/signal.h>
39+
#include <haproxy/ssl_sock.h>
3940
#include <haproxy/stconn.h>
4041
#include <haproxy/stream.h>
4142
#include <haproxy/systemd.h>
@@ -988,6 +989,73 @@ void mworker_prepare_master(void)
988989
LIST_APPEND(&proc_list, &tmproc->list);
989990
}
990991

992+
static void mworker_loop()
993+
{
994+
995+
/* Busy polling makes no sense in the master :-) */
996+
global.tune.options &= ~GTUNE_BUSY_POLLING;
997+
998+
999+
signal_unregister(SIGTTIN);
1000+
signal_unregister(SIGTTOU);
1001+
signal_unregister(SIGUSR1);
1002+
signal_unregister(SIGHUP);
1003+
signal_unregister(SIGQUIT);
1004+
1005+
signal_register_fct(SIGTERM, mworker_catch_sigterm, SIGTERM);
1006+
signal_register_fct(SIGUSR1, mworker_catch_sigterm, SIGUSR1);
1007+
signal_register_fct(SIGTTIN, mworker_broadcast_signal, SIGTTIN);
1008+
signal_register_fct(SIGTTOU, mworker_broadcast_signal, SIGTTOU);
1009+
signal_register_fct(SIGINT, mworker_catch_sigterm, SIGINT);
1010+
signal_register_fct(SIGHUP, mworker_catch_sighup, SIGHUP);
1011+
signal_register_fct(SIGUSR2, mworker_catch_sighup, SIGUSR2);
1012+
signal_register_fct(SIGCHLD, mworker_catch_sigchld, SIGCHLD);
1013+
1014+
mworker_unblock_signals();
1015+
mworker_cleantasks();
1016+
1017+
mworker_catch_sigchld(NULL); /* ensure we clean the children in case
1018+
some SIGCHLD were lost */
1019+
1020+
jobs++; /* this is the "master" job, we want to take care of the
1021+
signals even if there is no listener so the poll loop don't
1022+
leave */
1023+
1024+
fork_poller();
1025+
run_thread_poll_loop(NULL);
1026+
}
1027+
1028+
void mworker_run_master(void)
1029+
{
1030+
struct mworker_proc *child, *it;
1031+
1032+
proc_self->failedreloads = 0; /* reset the number of failure */
1033+
mworker_loop();
1034+
#if defined(USE_OPENSSL) && !defined(OPENSSL_NO_DH)
1035+
ssl_free_dh();
1036+
#endif
1037+
master = 0;
1038+
/* close useless master sockets */
1039+
mworker_cli_proxy_stop();
1040+
1041+
/* free proc struct of other processes */
1042+
list_for_each_entry_safe(child, it, &proc_list, list) {
1043+
/* close the FD of the master side for all
1044+
* workers, we don't need to close the worker
1045+
* side of other workers since it's done with
1046+
* the bind_proc */
1047+
if (child->ipc_fd[0] >= 0) {
1048+
close(child->ipc_fd[0]);
1049+
child->ipc_fd[0] = -1;
1050+
}
1051+
LIST_DELETE(&child->list);
1052+
mworker_free_child(child);
1053+
child = NULL;
1054+
}
1055+
/* master must leave */
1056+
exit(0);
1057+
}
1058+
9911059
static struct cfg_kw_list mworker_kws = {{ }, {
9921060
{ CFG_GLOBAL, "mworker-max-reloads", mworker_parse_global_max_reloads, KWF_DISCOVERY },
9931061
{ 0, NULL, NULL },

0 commit comments

Comments
 (0)