]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
REORG: mworker: move serializing functions to mworker.c
authorWilliam Lallemand <wlallemand@haproxy.com>
Mon, 1 Apr 2019 09:29:53 +0000 (11:29 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 1 Apr 2019 12:45:37 +0000 (14:45 +0200)
Move the 2 following functions to mworker.c:

void mworker_proc_list_to_env()
void mworker_env_to_proc_list()

Makefile
include/proto/mworker.h [new file with mode: 0644]
src/haproxy.c
src/mworker.c [new file with mode: 0644]

index 297d97c206cdccf08c4ce7ab3ff5d65fbd312b35..3bf540c1ec5552fafdff59631f4b42cf047a21e4 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -790,7 +790,8 @@ OBJS = src/proto_http.o src/cfgparse-listen.o src/proto_htx.o src/stream.o    \
        src/http.o src/hpack-dec.o src/action.o src/proto_udp.o src/http_acl.o \
        src/xxhash.o src/hpack-enc.o src/h2.o src/freq_ctr.o src/lru.o         \
        src/protocol.o src/arg.o src/hpack-huff.o src/hdr_idx.o src/base64.o   \
-       src/hash.o src/mailers.o src/activity.o src/http_msg.o src/version.o
+       src/hash.o src/mailers.o src/activity.o src/http_msg.o src/version.o   \
+       src/mworker.o
 
 EBTREE_OBJS = $(EBTREE_DIR)/ebtree.o $(EBTREE_DIR)/eb32sctree.o \
               $(EBTREE_DIR)/eb32tree.o $(EBTREE_DIR)/eb64tree.o \
diff --git a/include/proto/mworker.h b/include/proto/mworker.h
new file mode 100644 (file)
index 0000000..13e5c27
--- /dev/null
@@ -0,0 +1,19 @@
+/*
+ * Master Worker
+ *
+ * Copyright HAProxy Technologies 2019 - William Lallemand <wlallemand@haproxy.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ *
+ */
+
+#ifndef PROTO_MWORKER_H_
+#define PROTO_MWORKER_H_
+
+void mworker_proc_list_to_env();
+void mworker_env_to_proc_list();
+
+#endif /* PROTO_MWORKER_H_ */
index f0cb2baae372e28bbc18c7295c623b09eb07dfbd..85234720b2b169a010479e723cf00f117bcca101 100644 (file)
 #include <proto/http_rules.h>
 #include <proto/listener.h>
 #include <proto/log.h>
+#include <proto/mworker.h>
 #include <proto/pattern.h>
 #include <proto/protocol.h>
 #include <proto/proto_http.h>
@@ -542,71 +543,6 @@ static void mworker_kill(int sig)
        }
 }
 
-/*
- * serialize the proc list and put it in the environment
- */
-static void mworker_proc_list_to_env()
-{
-       char *msg = NULL;
-       struct mworker_proc *child;
-
-       list_for_each_entry(child, &proc_list, list) {
-               if (child->pid > -1)
-                       memprintf(&msg, "%s|type=%c;fd=%d;pid=%d;rpid=%d;reloads=%d;timestamp=%d", msg ? msg : "", child->type, child->ipc_fd[0], child->pid, child->relative_pid, child->reloads, child->timestamp);
-       }
-       if (msg)
-               setenv("HAPROXY_PROCESSES", msg, 1);
-}
-
-/*
- * unserialize the proc list from the environment
- */
-static void mworker_env_to_proc_list()
-{
-       char *msg, *token = NULL, *s1;
-
-       msg = getenv("HAPROXY_PROCESSES");
-       if (!msg)
-               return;
-
-       while ((token = strtok_r(msg, "|", &s1))) {
-               struct mworker_proc *child;
-               char *subtoken = NULL;
-               char *s2;
-
-               msg = NULL;
-
-               child = calloc(1, sizeof(*child));
-
-               while ((subtoken = strtok_r(token, ";", &s2))) {
-
-                       token = NULL;
-
-                       if (strncmp(subtoken, "type=", 5) == 0) {
-                               child->type = *(subtoken+5);
-                               if (child->type == 'm') /* we are in the master, assign it */
-                                       proc_self = child;
-                       } else if (strncmp(subtoken, "fd=", 3) == 0) {
-                               child->ipc_fd[0] = atoi(subtoken+3);
-                       } else if (strncmp(subtoken, "pid=", 4) == 0) {
-                               child->pid = atoi(subtoken+4);
-                       } else if (strncmp(subtoken, "rpid=", 5) == 0) {
-                               child->relative_pid = atoi(subtoken+5);
-                       } else if (strncmp(subtoken, "reloads=", 8) == 0) {
-                               /* we reloaded this process once more */
-                               child->reloads = atoi(subtoken+8) + 1;
-                       } else if (strncmp(subtoken, "timestamp=", 10) == 0) {
-                               child->timestamp = atoi(subtoken+10);
-                       }
-               }
-               if (child->pid)
-                       LIST_ADDQ(&proc_list, &child->list);
-               else
-                       free(child);
-       }
-
-       unsetenv("HAPROXY_PROCESSES");
-}
 
 /*
  * Upon a reload, the master worker needs to close all listeners FDs but the mworker_pipe
diff --git a/src/mworker.c b/src/mworker.c
new file mode 100644 (file)
index 0000000..2f0f09b
--- /dev/null
@@ -0,0 +1,88 @@
+/*
+ * Master Worker
+ *
+ * Copyright HAProxy Technologies 2019 - William Lallemand <wlallemand@haproxy.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ *
+ */
+
+#include <stdlib.h>
+#include <string.h>
+
+#include <common/mini-clist.h>
+
+#include <proto/mworker.h>
+
+#include <types/global.h>
+
+
+
+/*
+ * serialize the proc list and put it in the environment
+ */
+void mworker_proc_list_to_env()
+{
+       char *msg = NULL;
+       struct mworker_proc *child;
+
+       list_for_each_entry(child, &proc_list, list) {
+               if (child->pid > -1)
+                       memprintf(&msg, "%s|type=%c;fd=%d;pid=%d;rpid=%d;reloads=%d;timestamp=%d", msg ? msg : "", child->type, child->ipc_fd[0], child->pid, child->relative_pid, child->reloads, child->timestamp);
+       }
+       if (msg)
+               setenv("HAPROXY_PROCESSES", msg, 1);
+}
+
+/*
+ * unserialize the proc list from the environment
+ */
+void mworker_env_to_proc_list()
+{
+       char *msg, *token = NULL, *s1;
+
+       msg = getenv("HAPROXY_PROCESSES");
+       if (!msg)
+               return;
+
+       while ((token = strtok_r(msg, "|", &s1))) {
+               struct mworker_proc *child;
+               char *subtoken = NULL;
+               char *s2;
+
+               msg = NULL;
+
+               child = calloc(1, sizeof(*child));
+
+               while ((subtoken = strtok_r(token, ";", &s2))) {
+
+                       token = NULL;
+
+                       if (strncmp(subtoken, "type=", 5) == 0) {
+                               child->type = *(subtoken+5);
+                               if (child->type == 'm') /* we are in the master, assign it */
+                                       proc_self = child;
+                       } else if (strncmp(subtoken, "fd=", 3) == 0) {
+                               child->ipc_fd[0] = atoi(subtoken+3);
+                       } else if (strncmp(subtoken, "pid=", 4) == 0) {
+                               child->pid = atoi(subtoken+4);
+                       } else if (strncmp(subtoken, "rpid=", 5) == 0) {
+                               child->relative_pid = atoi(subtoken+5);
+                       } else if (strncmp(subtoken, "reloads=", 8) == 0) {
+                               /* we reloaded this process once more */
+                               child->reloads = atoi(subtoken+8) + 1;
+                       } else if (strncmp(subtoken, "timestamp=", 10) == 0) {
+                               child->timestamp = atoi(subtoken+10);
+                       }
+               }
+               if (child->pid)
+                       LIST_ADDQ(&proc_list, &child->list);
+               else
+                       free(child);
+       }
+
+       unsetenv("HAPROXY_PROCESSES");
+}