]> git.kaiwu.me - haproxy.git/commitdiff
DEBUG: support reading set-dumpable from HAPROXY_FORCE_DUMPABLE
authorWilly Tarreau <w@1wt.eu>
Tue, 6 Oct 2026 08:10:02 +0000 (10:10 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 6 Oct 2026 08:10:02 +0000 (10:10 +0200)
When debugging regtests, it is super complicated to get a core to be
dumped. It often requires to place a set-dumpable directive in the
config, but when it's generated it's really not convenient. A better
approach in this case is to read the value from an environment variable.

That's what this patch does, by accepting to preset the set-dumpable
options from the contents of HAPROXY_FORCE_DUMPABLE. It's a bit more
relaxed, though, as it accepts "off" to stay disabled, "libs" to just
load the libs, and anything else to enable.

The config and management docs were updated. This could be backported
to older versions if found helpful.

doc/configuration.txt
doc/management.txt
src/haproxy.c

index 514bbd67f8a73e9c0d497407c5cca2ada433ad2a..d7d25929660e146dca113f08736d317de835d2ce 100644 (file)
@@ -1093,6 +1093,18 @@ The variables in question are the following:
     migration if resources (such as maps or certificates) are in a path
     containing the branch number.
 
+The following variables may be read by haproxy to adjust its behavior:
+
+  * HAPROXY_FORCE_DUMPABLE: this allows to preset the equivalent of what the
+    global "set-dumpable" directive does, without having to touch the
+    configuration. This is essentially used with reg tests. The recognized
+    values are:
+       - libs: a copy of all dependencies is loaded into memory so as to be
+         preserved in core dumps
+       - off: does not enable dumpable (default)
+       - any other value (e.g. "on", "1", empty): enables set-dumpable, i.e.
+         will disable automatic chroot and try hard to enable core dumps.
+
 In addition, some pseudo-variables are internally resolved and may be used as
 regular variables. Pseudo-variables always start with a dot ('.'), and are the
 only ones where the dot is permitted. The current list of pseudo-variables is:
@@ -3272,7 +3284,12 @@ set-dumpable [ on | off | libs ]
   the issue. When trying to enable this option waiting for a rare issue to
   re-appear, it's often a good idea to first try to obtain such a dump by
   issuing, for example, "kill -11" to the "haproxy" process and verify that it
-  leaves a core where expected when dying.
+  leaves a core where expected when dying. Note that when debugging certain
+  setups, it is not necessarily convenient to modify the configuration nor the
+  command line to enable core dumps. This is for example the case with
+  generated configurations and regression testing. In this case, it is possible
+  to preset the set-dumpable argument in the HAPROXY_FORCE_DUMPABLE environment
+  variable, which accepts the same values.
 
 set-var <var-name> <expr>
   Sets the process-wide variable '<var-name>' to the result of the evaluation
index 0148b031b3b78f47eebefb71a903f30e4084f4fb..6bfeec6ca0da5517c7a2b4684813bf6d37a7edfc 100644 (file)
@@ -5275,6 +5275,14 @@ fast enough. This can happen during some attacks as well. Tx-Drp means that
 the output queues were full and packets had to be dropped. When using TCP it
 should be very rare, but will possibly indicate a saturated outgoing link.
 
+For more advanced debugging (e.g. crashes), core dumps might be needed. The
+global "set-dumpable" directive helps to re-enable them despite certain uid/gid
+and chroot changes. When editing the configuration is not an option, such as
+when dealing with generated configurations or regression tests, it is possible
+to set the HAPROXY_FORCE_DUMPABLE environment variable to one of the values
+accepted by "set-dumpable". Please consult the configuration manual for more
+information on this topic.
+
 
 13. Security considerations
 ---------------------------
index 772f788fabcf66b0e19d274b2a2b41957c752a21..537508729a48c442bba65d39770f803e27afbe45 100644 (file)
@@ -1449,6 +1449,7 @@ static void do_check_condition()
  */
 static void init_early(int argc, char **argv)
 {
+       const char *dumpable;
        char *tmp;
        int len;
 
@@ -1511,6 +1512,15 @@ static void init_early(int argc, char **argv)
                ha_alert("Cannot allocate memory for log_tag.\n");
                exit(EXIT_FAILURE);
        }
+
+       dumpable = getenv("HAPROXY_FORCE_DUMPABLE");
+       if (dumpable) {
+               /* "libs" only loads libs; "off" keeps disabled, other values enable */
+               if (strcmp(dumpable, "libs") == 0)
+                       global.tune.options |= GTUNE_SET_DUMPABLE | GTUNE_COLLECT_LIBS;
+               else if (strcmp(dumpable, "off") != 0)
+                       global.tune.options |= GTUNE_SET_DUMPABLE;
+       }
 }
 
 void haproxy_init_args(int argc, char **argv)