]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: mworker/cli: rename and clean mworker_cli_sockpair_new
authorValentine Krasnobaeva <vkrasnobaeva@haproxy.com>
Wed, 2 Oct 2024 12:49:30 +0000 (14:49 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 16 Oct 2024 20:02:39 +0000 (22:02 +0200)
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
src/cli.c
src/haproxy.c

index 537f306e46cbb296067c7227ef2daae433aa6f1b..17a8c6557c70bc715af05db1e7cf1e0cd2502b15 100644 (file)
@@ -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;
index ea9fcd6572392078bab42af5dbefd18d0f1738c5..e60113d927c6b53d12a00c3b5bb524778f39c970 100644 (file)
--- a/src/cli.c
+++ b/src/cli.c
@@ -3487,10 +3487,11 @@ err:
 }
 
 /*
- * Create a new CLI socket using a socketpair for a worker process
- * <mworker_proc> is the process structure, and <proc> 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 <proc> 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;
index 31fb7fe5cb067d2c16110aa96b847687965bc6a8..62e1732925b8fa4639cc85e7b4131158a83db201 100644 (file)
@@ -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);
        }