Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
REORG: mworker: move mworker_cleanlisteners to mworker.c
  • Loading branch information
wlallemand authored and wtarreau committed Apr 1, 2019
1 parent e25473c commit 9001ce8
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 52 deletions.
2 changes: 2 additions & 0 deletions include/proto/mworker.h
Expand Up @@ -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_ */
52 changes: 0 additions & 52 deletions src/haproxy.c
Expand Up @@ -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
Expand Down
53 changes: 53 additions & 0 deletions src/mworker.c
Expand Up @@ -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)
Expand Down Expand Up @@ -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.