]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: diag: create cfgdiag module
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Tue, 30 Mar 2021 15:34:24 +0000 (17:34 +0200)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Thu, 1 Apr 2021 16:03:37 +0000 (18:03 +0200)
This module is intended to serve as a placeholder for various
diagnostics executed after the configuration file has been fully loaded.

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

index e8110bd2e764e01b3584978819f046e09d3c5af7..2ff6cd38bca08ea108a0c3913c59292e8bfbd9ac 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -878,7 +878,7 @@ OBJS += src/mux_h2.o src/mux_fcgi.o src/http_ana.o src/stream.o                \
         src/ebistree.o src/auth.o src/wdt.o src/http_acl.o                     \
         src/hpack-enc.o src/hpack-huff.o src/ebtree.o src/base64.o             \
         src/hash.o src/dgram.o src/version.o src/fix.o src/mqtt.o src/dns.o    \
-        src/server_state.o src/proto_uxdg.o src/init.o
+        src/server_state.o src/proto_uxdg.o src/init.o src/cfgdiag.o
 
 ifneq ($(TRACE),)
 OBJS += src/calltrace.o
diff --git a/include/haproxy/cfgdiag.h b/include/haproxy/cfgdiag.h
new file mode 100644 (file)
index 0000000..6ec84b1
--- /dev/null
@@ -0,0 +1,11 @@
+#ifndef _HAPROXY_CFGDIAG_H
+#define _HAPROXY_CFGDIAG_H
+
+/* Placeholder to execute various diagnostic checks after the configuration file
+ * has been fully parsed. It will output a warning for each diagnostic found.
+ *
+ * Returns 0 if no diagnostic message has been found else 1.
+ */
+int cfg_run_diagnostics();
+
+#endif /* _HAPROXY_CFGDIAG_H */
diff --git a/src/cfgdiag.c b/src/cfgdiag.c
new file mode 100644 (file)
index 0000000..35c8e67
--- /dev/null
@@ -0,0 +1,45 @@
+#include <stdarg.h>
+#include <stdlib.h>
+
+#include <haproxy/cfgdiag.h>
+#include <haproxy/log.h>
+
+/* Use this fonction to emit diagnostic.
+ * This can be used as a shortcut to set value pointed by <ret> to 1 at the
+ * same time.
+ */
+static inline void diag_warning(int *ret, char *fmt, ...)
+{
+       va_list argp;
+
+       va_start(argp, fmt);
+       *ret = 1;
+       _ha_vdiag_warning(fmt, argp);
+       va_end(argp);
+}
+
+/* Use this for dynamic allocation in diagnostics.
+ * In case of allocation failure, this will immediately terminates haproxy.
+ */
+static inline void *diag_alloc(size_t size)
+{
+       void *out = NULL;
+
+       if (!(out = malloc(size))) {
+               fprintf(stderr, "out of memory\n");
+               exit(1);
+       }
+
+       return out;
+}
+
+/* Placeholder to execute various diagnostic checks after the configuration file
+ * has been fully parsed. It will output a warning for each diagnostic found.
+ *
+ * Returns 0 if no diagnostic message has been found else 1.
+ */
+int cfg_run_diagnostics()
+{
+       int ret = 0;
+       return ret;
+}
index aeb92e6b0761790e52b471fbd16f9725d303ed4e..e7d30b01feca023d7b79ce3e7a78da1448eef264 100644 (file)
@@ -87,6 +87,7 @@
 #include <haproxy/auth.h>
 #include <haproxy/base64.h>
 #include <haproxy/capture-t.h>
+#include <haproxy/cfgdiag.h>
 #include <haproxy/cfgparse.h>
 #include <haproxy/chunk.h>
 #include <haproxy/cli.h>
@@ -1806,6 +1807,10 @@ static void init(int argc, char **argv)
                exit(2);
        }
 
+       if (global.mode & MODE_DIAG) {
+               cfg_run_diagnostics();
+       }
+
        /* now we know the buffer size, we can initialize the channels and buffers */
        init_buffer();