]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: init: allow a fileless init mode
authorFrederic Lecaille <flecaille@haproxy.com>
Wed, 11 Feb 2026 10:11:16 +0000 (11:11 +0100)
committerWilly Tarreau <w@1wt.eu>
Thu, 19 Feb 2026 13:46:49 +0000 (14:46 +0100)
This patch provides the possibility to initialize haproxy without
configuration file. This may be identified by the new global and exported
<fileless_mode> and <fileless_cfg> variables which may be used to
provide a struct cfgfile to haproxy by others means than a physical
file (built in memory).
When enabled, this fileless mode skips all the configuration files
parsing.

include/haproxy/global.h
src/haproxy.c

index b4a7a406bc29c41c8c2f1d1ebd87ef220f6cc670..522af4162745f754e03680803967d0c8971d828d 100644 (file)
@@ -24,6 +24,7 @@
 
 #include <haproxy/api-t.h>
 #include <haproxy/global-t.h>
+#include <haproxy/cfgparse.h>
 
 extern struct global global;
 extern int  pid;                /* current process id */
@@ -54,6 +55,8 @@ extern char **old_argv;
 extern const char *old_unixsocket;
 extern int daemon_fd[2];
 extern int devnullfd;
+extern int fileless_mode;
+extern struct cfgfile fileless_cfg;
 
 struct proxy;
 struct server;
index d1da0c3e30917e2900c3ea20b855d4a698b2cbb6..c7e89ae1ead959db29fe7790b820b0363d7201b7 100644 (file)
@@ -150,6 +150,8 @@ char **init_env;            /* to keep current process env variables backup */
 int  pidfd = -1;               /* FD to keep PID */
 int daemon_fd[2] = {-1, -1};   /* pipe to communicate with parent process */
 int devnullfd = -1;
+int fileless_mode;
+struct cfgfile fileless_cfg;
 
 static int stopped_tgroups;
 static int stop_detected;
@@ -3375,8 +3377,16 @@ int main(int argc, char **argv)
        if (backup_env() != 0)
                exit(EXIT_FAILURE);
 
-       /* parse conf in discovery mode and set modes from config */
-       read_cfg_in_discovery_mode(argc, argv);
+       if (!fileless_mode)
+               /* parse conf in discovery mode and set modes from config */
+               read_cfg_in_discovery_mode(argc, argv);
+       else {
+               int ret;
+
+               ret = parse_cfg(&fileless_cfg);
+               if (ret != 0)
+                       exit(EXIT_FAILURE);
+       }
 
        /* From this stage all runtime modes are known. So let's do below some
         * preparation steps and then let's apply all discovered modes.
@@ -3418,8 +3428,10 @@ int main(int argc, char **argv)
                mworker_apply_master_worker_mode();
        }
 
-       /* Worker, daemon, foreground modes read the rest of the config */
-       if (!master) {
+       /* Worker, daemon, foreground, configuration with files modes read the rest
+        * of the config.
+        */
+       if (!master && !fileless_mode) {
                usermsgs_clr("config");
                if (global.mode & MODE_MWORKER) {
                        if (clean_env() != 0) {