From: Willy Tarreau Date: Tue, 6 Oct 2026 08:10:02 +0000 (+0200) Subject: DEBUG: support reading set-dumpable from HAPROXY_FORCE_DUMPABLE X-Git-Tag: v3.5-dev9~202 X-Git-Url: https://git.kaiwu.me/$%7BGITURL%7D$%7Bcid%7D?a=commitdiff_plain;h=bd884a20377963fda9031c878ec4020b84da1f77;p=haproxy.git DEBUG: support reading set-dumpable from HAPROXY_FORCE_DUMPABLE 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. --- diff --git a/doc/configuration.txt b/doc/configuration.txt index 514bbd67f..d7d259296 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -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 Sets the process-wide variable '' to the result of the evaluation diff --git a/doc/management.txt b/doc/management.txt index 0148b031b..6bfeec6ca 100644 --- a/doc/management.txt +++ b/doc/management.txt @@ -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 --------------------------- diff --git a/src/haproxy.c b/src/haproxy.c index 772f788fa..537508729 100644 --- a/src/haproxy.c +++ b/src/haproxy.c @@ -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)