From 6013f4baeb66c15d0c643082ff7850d9f7d2b1c7 Mon Sep 17 00:00:00 2001 From: Frederic Lecaille Date: Wed, 11 Feb 2026 11:11:16 +0100 Subject: [PATCH] MINOR: init: allow a fileless init mode This patch provides the possibility to initialize haproxy without configuration file. This may be identified by the new global and exported and 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 | 3 +++ src/haproxy.c | 20 ++++++++++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/include/haproxy/global.h b/include/haproxy/global.h index b4a7a406b..522af4162 100644 --- a/include/haproxy/global.h +++ b/include/haproxy/global.h @@ -24,6 +24,7 @@ #include #include +#include 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; diff --git a/src/haproxy.c b/src/haproxy.c index d1da0c3e3..c7e89ae1e 100644 --- a/src/haproxy.c +++ b/src/haproxy.c @@ -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) { -- 2.47.3