]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
REORG: startup: move mworker_prepare_master in mworker.c
authorValentine Krasnobaeva <vkrasnobaeva@haproxy.com>
Fri, 22 Nov 2024 22:07:00 +0000 (23:07 +0100)
committerWilliam Lallemand <wlallemand@haproxy.com>
Mon, 25 Nov 2024 14:20:24 +0000 (15:20 +0100)
mworker_prepare_master() performs some preparation routines for the new worker
process, which will be forked during the startup. It's called only in
master-worker mode, so let's move it in mworker.c.

include/haproxy/mworker.h
src/haproxy.c
src/mworker.c

index 7d2fa251e6d592184531e1d3ba8ba77dba1a9ee5..f2c60a333d31c3141600d35053ebb94fb5d1635e 100644 (file)
@@ -51,4 +51,6 @@ void mworker_cleanup_proc();
 
 void mworker_create_master_cli(void);
 
+void mworker_prepare_master(void);
+
 #endif /* _HAPROXY_MWORKER_H_ */
index a2dda006e30911ab9480f111ff5b94e82822a349..f8d987ff21e1f388033265955d404ddc99821c85 100644 (file)
@@ -1960,50 +1960,6 @@ static void generate_random_cluster_secret()
        cluster_secret_isset = 1;
 }
 
-/* This function fills proc_list for master-worker mode and creates a sockpair,
- * copied after master-worker fork() to each process context to enable master
- * CLI at worker side (worker can send its status to master).It only returns if
- * everything is OK. If something fails, it exits.
- */
-static void mworker_prepare_master()
-{
-       struct mworker_proc *tmproc;
-
-       setenv("HAPROXY_MWORKER", "1", 1);
-
-       if (getenv("HAPROXY_MWORKER_REEXEC") == NULL) {
-
-               tmproc = mworker_proc_new();
-               if (!tmproc) {
-                       ha_alert("Cannot allocate process structures.\n");
-                       exit(EXIT_FAILURE);
-               }
-               tmproc->options |= PROC_O_TYPE_MASTER; /* master */
-               tmproc->pid = pid;
-               tmproc->timestamp = start_date.tv_sec;
-               proc_self = tmproc;
-
-               LIST_APPEND(&proc_list, &tmproc->list);
-       }
-
-       tmproc = mworker_proc_new();
-       if (!tmproc) {
-               ha_alert("Cannot allocate process structures.\n");
-               exit(EXIT_FAILURE);
-       }
-       /* worker */
-       tmproc->options |= (PROC_O_TYPE_WORKER | PROC_O_INIT);
-
-       /* create a sockpair to copy it via fork(), thus it will be in
-        * master and in worker processes
-        */
-       if (socketpair(AF_UNIX, SOCK_STREAM, 0, tmproc->ipc_fd) < 0) {
-               ha_alert("Cannot create worker master CLI socketpair.\n");
-               exit(EXIT_FAILURE);
-       }
-       LIST_APPEND(&proc_list, &tmproc->list);
-}
-
 static void mworker_run_master()
 {
        struct mworker_proc *child, *it;
index ebe032efd13ddbd28465693e6c09d5c47811cef2..8fd0c02a6c12703f8919e1ce8d6a4e760ead5c64 100644 (file)
@@ -944,6 +944,50 @@ void mworker_create_master_cli(void)
        }
 }
 
+/* This function fills proc_list for master-worker mode and creates a sockpair,
+ * copied after master-worker fork() to each process context to enable master
+ * CLI at worker side (worker can send its status to master).It only returns if
+ * everything is OK. If something fails, it exits.
+ */
+void mworker_prepare_master(void)
+{
+       struct mworker_proc *tmproc;
+
+       setenv("HAPROXY_MWORKER", "1", 1);
+
+       if (getenv("HAPROXY_MWORKER_REEXEC") == NULL) {
+
+               tmproc = mworker_proc_new();
+               if (!tmproc) {
+                       ha_alert("Cannot allocate process structures.\n");
+                       exit(EXIT_FAILURE);
+               }
+               tmproc->options |= PROC_O_TYPE_MASTER; /* master */
+               tmproc->pid = pid;
+               tmproc->timestamp = start_date.tv_sec;
+               proc_self = tmproc;
+
+               LIST_APPEND(&proc_list, &tmproc->list);
+       }
+
+       tmproc = mworker_proc_new();
+       if (!tmproc) {
+               ha_alert("Cannot allocate process structures.\n");
+               exit(EXIT_FAILURE);
+       }
+       /* worker */
+       tmproc->options |= (PROC_O_TYPE_WORKER | PROC_O_INIT);
+
+       /* create a sockpair to copy it via fork(), thus it will be in
+        * master and in worker processes
+        */
+       if (socketpair(AF_UNIX, SOCK_STREAM, 0, tmproc->ipc_fd) < 0) {
+               ha_alert("Cannot create worker master CLI socketpair.\n");
+               exit(EXIT_FAILURE);
+       }
+       LIST_APPEND(&proc_list, &tmproc->list);
+}
+
 static struct cfg_kw_list mworker_kws = {{ }, {
        { CFG_GLOBAL, "mworker-max-reloads", mworker_parse_global_max_reloads, KWF_DISCOVERY },
        { 0, NULL, NULL },