From cc1a631bebb74e06639220b652a79c01f30d2df2 Mon Sep 17 00:00:00 2001 From: Valentine Krasnobaeva Date: Wed, 2 Oct 2024 14:49:30 +0200 Subject: [PATCH] MINOR: mworker/cli: rename and clean mworker_cli_sockpair_new Let's rename mworker_cli_sockpair_new() to mworker_cli_global_proxy_new_listener() to outline that this function creates the GLOBAL proxy, allocates the listener with "master-socket" bind conf and attaches this listener to this GLOBAL proxy. Listener is bound to ipc_fd[1] of the sockpair inherited in master and in worker (master CLI sockpair). --- include/haproxy/cli.h | 2 +- src/cli.c | 17 +++++++++-------- src/haproxy.c | 3 +-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/include/haproxy/cli.h b/include/haproxy/cli.h index 537f306e4..17a8c6557 100644 --- a/include/haproxy/cli.h +++ b/include/haproxy/cli.h @@ -43,7 +43,7 @@ int cli_parse_default(char **args, char *payload, struct appctx *appctx, void *p int mworker_cli_proxy_create(void); struct bind_conf *mworker_cli_master_proxy_new_listener(char *line); -int mworker_cli_sockpair_new(struct mworker_proc *mworker_proc, int proc); +int mworker_cli_global_proxy_new_listener(struct mworker_proc *proc); void mworker_cli_proxy_stop(void); extern struct bind_conf *mcli_reload_bind_conf; diff --git a/src/cli.c b/src/cli.c index ea9fcd657..e60113d92 100644 --- a/src/cli.c +++ b/src/cli.c @@ -3487,10 +3487,11 @@ struct bind_conf *mworker_cli_master_proxy_new_listener(char *line) } /* - * Create a new CLI socket using a socketpair for a worker process - * is the process structure, and is the process number + * Creates a sockpair, a "master-socket" bind conf and a listener. Assigns + * this new listener to the one "end" of the given process sockpair in + * order to have a new master CLI listening socket for this process. */ -int mworker_cli_sockpair_new(struct mworker_proc *mworker_proc, int proc) +int mworker_cli_global_proxy_new_listener(struct mworker_proc *proc) { struct bind_conf *bind_conf; struct listener *l; @@ -3498,7 +3499,7 @@ int mworker_cli_sockpair_new(struct mworker_proc *mworker_proc, int proc) char *err = NULL; /* master pipe to ensure the master is still alive */ - if (socketpair(AF_UNIX, SOCK_STREAM, 0, mworker_proc->ipc_fd) < 0) { + if (socketpair(AF_UNIX, SOCK_STREAM, 0, proc->ipc_fd) < 0) { ha_alert("Cannot create worker socketpair.\n"); return -1; } @@ -3519,14 +3520,14 @@ int mworker_cli_sockpair_new(struct mworker_proc *mworker_proc, int proc) bind_conf->level |= ACCESS_LVL_ADMIN; /* TODO: need to lower the rights with a CLI keyword*/ bind_conf->level |= ACCESS_FD_LISTENERS; - if (!memprintf(&path, "sockpair@%d", mworker_proc->ipc_fd[1])) { + if (!memprintf(&path, "sockpair@%d", proc->ipc_fd[1])) { ha_alert("Cannot allocate listener.\n"); goto error; } if (!str2listener(path, global.cli_fe, bind_conf, "master-socket", 0, &err)) { free(path); - ha_alert("Cannot create a CLI sockpair listener for process #%d\n", proc); + ha_alert("Cannot create a CLI sockpair listener.\n"); goto error; } ha_free(&path); @@ -3548,8 +3549,8 @@ int mworker_cli_sockpair_new(struct mworker_proc *mworker_proc, int proc) return 0; error: - close(mworker_proc->ipc_fd[0]); - close(mworker_proc->ipc_fd[1]); + close(proc->ipc_fd[0]); + close(proc->ipc_fd[1]); free(err); return -1; diff --git a/src/haproxy.c b/src/haproxy.c index 31fb7fe5c..62e173292 100644 --- a/src/haproxy.c +++ b/src/haproxy.c @@ -2096,9 +2096,8 @@ static void init(int argc, char **argv) } tmproc->options |= PROC_O_TYPE_WORKER; /* worker */ - if (mworker_cli_sockpair_new(tmproc, 0) < 0) { + if (mworker_cli_global_proxy_new_listener(tmproc) < 0) exit(EXIT_FAILURE); - } LIST_APPEND(&proc_list, &tmproc->list); }