]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: httpterm: add support httpterm run mode
authorFrederic Lecaille <flecaille@haproxy.com>
Mon, 26 Jan 2026 15:37:39 +0000 (16:37 +0100)
committerFrederic Lecaille <flecaille@haproxy.com>
Thu, 29 Jan 2026 19:35:50 +0000 (20:35 +0100)
Rely on the binary name to decide the mode which will be used by
the built process. If its name begin with "httpterm" substring,
the httpterm mode will be run. This is done by init_early() function
which set httpterm_mode to 1 if this is the case.

When in httpterm mode, the process call init_args() as for haproxy
but skip the haproxy command line arguments parsing. This is done
by init_httpterm_cfg() which parse the httpterm command line arguments.
This function also initalize the struct cfgfile httpterm_cfg variable.
Then parse_cfg() is called to by main() to configure the frontend
used by httpterm, depending on the arguments of its command line.

backup_env() is skipped in this httpterm mode. This is also the case
for the master worker which is not initialized.

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

index b4a7a406bc29c41c8c2f1d1ebd87ef220f6cc670..ef6edc7f3781ab0ec10589f6f62859c3dd88cf76 100644 (file)
@@ -54,6 +54,8 @@ extern char **old_argv;
 extern const char *old_unixsocket;
 extern int daemon_fd[2];
 extern int devnullfd;
+extern int httpterm_mode;
+extern struct cfgfile httpterm_cfg;
 
 struct proxy;
 struct server;
index c4a755f5e654e6321baa2a7d6d4f345d03481eba..3ee681e06bc113196869a7c1085f856e9a08b290 100644 (file)
@@ -88,6 +88,7 @@
 #include <haproxy/filters.h>
 #include <haproxy/global.h>
 #include <haproxy/hlua.h>
+#include <haproxy/hstream.h>
 #include <haproxy/http_rules.h>
 #include <haproxy/limits.h>
 #if defined(USE_LINUX_CAP)
@@ -150,6 +151,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 httpterm_mode;
+struct cfgfile httpterm_cfg;
 
 static int stopped_tgroups;
 static int stop_detected;
@@ -1439,6 +1442,7 @@ static void init_early(int argc, char **argv)
                exit(EXIT_FAILURE);
        }
 
+       httpterm_mode = !strncmp(progname, "httpterm", strlen("httpterm"));
        chunk_initlen(&global.log_tag, strdup(progname), len, len);
 }
 
@@ -1482,6 +1486,9 @@ static void init_args(int argc, char **argv)
        /* Use zero-copy forwarding by default */
        global.tune.no_zero_copy_fwd = 0;
 
+       if (httpterm_mode)
+               return;
+
        /* keep a copy of original arguments for the master process */
        old_argv = copy_argv(argc, argv);
        if (!old_argv) {
@@ -3273,6 +3280,9 @@ int main(int argc, char **argv)
 
        RUN_INITCALLS(STG_INIT);
 
+       if (httpterm_mode)
+               init_httpterm_cfg(argc, argv, &httpterm_cfg);
+
        /* Late init step: SSL crypto libs init and check, Lua lib init, ACL init,
         * set modes from cmdline and change dir, if this option is provided via
         * cmdline.
@@ -3311,11 +3321,14 @@ int main(int argc, char **argv)
        /* backup initial process env, because parse_cfg() could modify it with
         * setenv/unsetenv/presetenv/resetenv keywords.
         */
-       if (backup_env() != 0)
+       if (!httpterm_mode && backup_env() != 0)
                exit(EXIT_FAILURE);
 
-       /* parse conf in discovery mode and set modes from config */
-       read_cfg_in_discovery_mode(argc, argv);
+       if (!httpterm_mode)
+               /* parse conf in discovery mode and set modes from config */
+               read_cfg_in_discovery_mode(argc, argv);
+       else
+               parse_cfg(&httpterm_cfg);
 
        /* From this stage all runtime modes are known. So let's do below some
         * preparation steps and then let's apply all discovered modes.
@@ -3358,7 +3371,7 @@ int main(int argc, char **argv)
        }
 
        /* Worker, daemon, foreground modes read the rest of the config */
-       if (!master) {
+       if (!master && !httpterm_mode) {
                usermsgs_clr("config");
                if (global.mode & MODE_MWORKER) {
                        if (clean_env() != 0) {