Skip to content
Permalink
Browse files

REORG: mworker: move mworker_cleanlisteners to mworker.c

  • Loading branch information...
wlallemand authored and Willy Tarreau committed Apr 1, 2019
1 parent e25473c commit 9001ce8c2f32dc79bf7fbc78b0123a80a8d05991
Showing with 55 additions and 52 deletions.
  1. +2 −0 include/proto/mworker.h
  2. +0 −52 src/haproxy.c
  3. +53 −0 src/mworker.c
@@ -29,6 +29,8 @@ void mworker_catch_sigchld(struct sig_handler *sh);
void mworker_accept_wrapper(int fd);
void mworker_pipe_register();

void mworker_cleanlisteners();

extern int *children; /* store PIDs of children in master workers mode */

#endif /* PROTO_MWORKER_H_ */
@@ -494,58 +494,6 @@ int tell_old_pids(int sig)
return ret;
}


/*
* Upon a reload, the master worker needs to close all listeners FDs but the mworker_pipe
* fd, and the FD provided by fd@
*/
static void mworker_cleanlisteners()
{
struct listener *l, *l_next;
struct proxy *curproxy;
struct peers *curpeers;

/* we might have to unbind some peers sections from some processes */
for (curpeers = cfg_peers; curpeers; curpeers = curpeers->next) {
if (!curpeers->peers_fe)
continue;

stop_proxy(curpeers->peers_fe);
/* disable this peer section so that it kills itself */
signal_unregister_handler(curpeers->sighandler);
task_delete(curpeers->sync_task);
task_free(curpeers->sync_task);
curpeers->sync_task = NULL;
task_free(curpeers->peers_fe->task);
curpeers->peers_fe->task = NULL;
curpeers->peers_fe = NULL;
}

for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) {
int listen_in_master = 0;

list_for_each_entry_safe(l, l_next, &curproxy->conf.listeners, by_fe) {
/* remove the listener, but not those we need in the master... */
if (!(l->options & LI_O_MWORKER)) {
/* unbind the listener but does not close if
the FD is inherited with fd@ from the parent
process */
if (l->options & LI_O_INHERITED)
unbind_listener_no_close(l);
else
unbind_listener(l);
delete_listener(l);
} else {
listen_in_master = 1;
}
}
/* if the proxy shouldn't be in the master, we stop it */
if (!listen_in_master)
curproxy->state = PR_STSTOPPED;
}
}


/*
* remove a pid forom the olpid array and decrease nb_oldpids
* return 1 pid was found otherwise return 0
@@ -26,6 +26,8 @@
#include <proto/signal.h>

#include <types/global.h>
#include <types/peers.h>
#include <proto/proxy.h>
#include <types/signal.h>

#if defined(USE_SYSTEMD)
@@ -301,3 +303,54 @@ void mworker_pipe_register()
fd_insert(proc_self->ipc_fd[1], fdtab[proc_self->ipc_fd[1]].owner, mworker_accept_wrapper, 1);
fd_want_recv(proc_self->ipc_fd[1]);
}

/* ----- proxies ----- */
/*
* Upon a reload, the master worker needs to close all listeners FDs but the mworker_pipe
* fd, and the FD provided by fd@
*/
void mworker_cleanlisteners()
{
struct listener *l, *l_next;
struct proxy *curproxy;
struct peers *curpeers;

/* we might have to unbind some peers sections from some processes */
for (curpeers = cfg_peers; curpeers; curpeers = curpeers->next) {
if (!curpeers->peers_fe)
continue;

stop_proxy(curpeers->peers_fe);
/* disable this peer section so that it kills itself */
signal_unregister_handler(curpeers->sighandler);
task_delete(curpeers->sync_task);
task_free(curpeers->sync_task);
curpeers->sync_task = NULL;
task_free(curpeers->peers_fe->task);
curpeers->peers_fe->task = NULL;
curpeers->peers_fe = NULL;
}

for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) {
int listen_in_master = 0;

list_for_each_entry_safe(l, l_next, &curproxy->conf.listeners, by_fe) {
/* remove the listener, but not those we need in the master... */
if (!(l->options & LI_O_MWORKER)) {
/* unbind the listener but does not close if
the FD is inherited with fd@ from the parent
process */
if (l->options & LI_O_INHERITED)
unbind_listener_no_close(l);
else
unbind_listener(l);
delete_listener(l);
} else {
listen_in_master = 1;
}
}
/* if the proxy shouldn't be in the master, we stop it */
if (!listen_in_master)
curproxy->state = PR_STSTOPPED;
}
}

0 comments on commit 9001ce8

Please sign in to comment.
You can’t perform that action at this time.