mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-08-07 07:37:02 +02:00
MINOR: startup: encapsulate master's code in run_master
Let's encapsulate master's code (steps which it does before entering in its polling loop and deinitialization routines after) in a separate run_master() function. This makes the code of main() more readable. In future we plan to put in run_master() more master process related code, in order to clean completely init_step_2(), init_step_3() and init_step_4().
This commit is contained in:
parent
e5cd81cf8f
commit
1cee184145
@ -2022,6 +2022,45 @@ static void prepare_master()
|
|||||||
LIST_APPEND(&proc_list, &tmproc->list);
|
LIST_APPEND(&proc_list, &tmproc->list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void run_master()
|
||||||
|
{
|
||||||
|
struct mworker_proc *child, *it;
|
||||||
|
|
||||||
|
if ((!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE)) &&
|
||||||
|
(global.mode & MODE_DAEMON)) {
|
||||||
|
/* detach from the tty, this is required to properly daemonize. */
|
||||||
|
if ((getenv("HAPROXY_MWORKER_REEXEC") == NULL))
|
||||||
|
stdio_quiet(-1);
|
||||||
|
global.mode &= ~MODE_VERBOSE;
|
||||||
|
global.mode |= MODE_QUIET; /* ensure that we won't say anything from now */
|
||||||
|
}
|
||||||
|
proc_self->failedreloads = 0; /* reset the number of failure */
|
||||||
|
mworker_loop();
|
||||||
|
#if defined(USE_OPENSSL) && !defined(OPENSSL_NO_DH)
|
||||||
|
ssl_free_dh();
|
||||||
|
#endif
|
||||||
|
master = 0;
|
||||||
|
/* close useless master sockets */
|
||||||
|
mworker_cli_proxy_stop();
|
||||||
|
|
||||||
|
/* free proc struct of other processes */
|
||||||
|
list_for_each_entry_safe(child, it, &proc_list, list) {
|
||||||
|
/* close the FD of the master side for all
|
||||||
|
* workers, we don't need to close the worker
|
||||||
|
* side of other workers since it's done with
|
||||||
|
* the bind_proc */
|
||||||
|
if (child->ipc_fd[0] >= 0) {
|
||||||
|
close(child->ipc_fd[0]);
|
||||||
|
child->ipc_fd[0] = -1;
|
||||||
|
}
|
||||||
|
LIST_DELETE(&child->list);
|
||||||
|
mworker_free_child(child);
|
||||||
|
child = NULL;
|
||||||
|
}
|
||||||
|
/* master must leave */
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This function does daemonization fork. It only returns if everything is OK.
|
* This function does daemonization fork. It only returns if everything is OK.
|
||||||
* If something fails, it exits.
|
* If something fails, it exits.
|
||||||
@ -3704,44 +3743,13 @@ int main(int argc, char **argv)
|
|||||||
*/
|
*/
|
||||||
step_init_4();
|
step_init_4();
|
||||||
|
|
||||||
|
/* Master enters in its polling loop */
|
||||||
if (master) {
|
if (master) {
|
||||||
struct mworker_proc *child, *it;
|
run_master();
|
||||||
|
/* never get there in master context */
|
||||||
if ((!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE)) &&
|
|
||||||
(global.mode & MODE_DAEMON)) {
|
|
||||||
/* detach from the tty, this is required to properly daemonize. */
|
|
||||||
if ((getenv("HAPROXY_MWORKER_REEXEC") == NULL))
|
|
||||||
stdio_quiet(-1);
|
|
||||||
global.mode &= ~MODE_VERBOSE;
|
|
||||||
global.mode |= MODE_QUIET; /* ensure that we won't say anything from now */
|
|
||||||
}
|
|
||||||
proc_self->failedreloads = 0; /* reset the number of failure */
|
|
||||||
mworker_loop();
|
|
||||||
#if defined(USE_OPENSSL) && !defined(OPENSSL_NO_DH)
|
|
||||||
ssl_free_dh();
|
|
||||||
#endif
|
|
||||||
master = 0;
|
|
||||||
/* close useless master sockets */
|
|
||||||
mworker_cli_proxy_stop();
|
|
||||||
|
|
||||||
/* free proc struct of other processes */
|
|
||||||
list_for_each_entry_safe(child, it, &proc_list, list) {
|
|
||||||
/* close the FD of the master side for all
|
|
||||||
* workers, we don't need to close the worker
|
|
||||||
* side of other workers since it's done with
|
|
||||||
* the bind_proc */
|
|
||||||
if (child->ipc_fd[0] >= 0) {
|
|
||||||
close(child->ipc_fd[0]);
|
|
||||||
child->ipc_fd[0] = -1;
|
|
||||||
}
|
|
||||||
LIST_DELETE(&child->list);
|
|
||||||
mworker_free_child(child);
|
|
||||||
child = NULL;
|
|
||||||
}
|
|
||||||
/* master must leave */
|
|
||||||
exit(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* End of initialization for standalone and worker modes */
|
||||||
if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE)) {
|
if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE)) {
|
||||||
devnullfd = open("/dev/null", (O_RDWR | O_CLOEXEC), 0);
|
devnullfd = open("/dev/null", (O_RDWR | O_CLOEXEC), 0);
|
||||||
if (devnullfd < 0) {
|
if (devnullfd < 0) {
|
||||||
|
Loading…
Reference in New Issue
Block a user