]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: startup: allow hap_register_feature() to enable a feature in the list
authorWilliam Lallemand <wlallemand@haproxy.com>
Thu, 13 Feb 2025 23:00:28 +0000 (00:00 +0100)
committerWilliam Lallemand <wlallemand@haproxy.com>
Thu, 13 Feb 2025 23:09:17 +0000 (00:09 +0100)
This patch allows hap_register_feature() to enable a feature in the list
which was already registered and marked disabled.

This way we could enable automatically some features under certain
condition without the need of the USE argument with make and correctly
report its activation.

src/haproxy.c

index 52ee3dbd2916b914d4876d68a5c3847da505c5be..8bcd30ab1e3c57dd82ea046f45a521503217e9a3 100644 (file)
@@ -347,13 +347,30 @@ void hap_register_feature(const char *name)
        static int must_free = 0;
        int new_len = strlen(build_features) + 2 + strlen(name);
        char *new_features;
+       char *found, *endp;
 
        new_features = malloc(new_len + 1);
        if (!new_features)
                return;
 
        strlcpy2(new_features, build_features, new_len);
-       snprintf(new_features, new_len + 1, "%s +%s", build_features, name);
+
+       /* look if the string already exists */
+       /* must be a complete feature name with a space of end of string behind (eg OPENSSL vs OPENSSL_AWSLC) */
+       found = strstr(new_features, name);
+       endp = found+strlen(name);
+
+       if (found && (*endp == ' ' || *endp == '\0')) {
+
+               /* if the feature name was found with a '-' replace it by a '+' */
+               if ((found-1 >= new_features) && (*(found-1) == '-')) {
+                       *(found-1) = '+';
+               }
+
+       } else {
+               /* if we didn't find the feature add it to the string */
+               snprintf(new_features, new_len + 1, "%s +%s", build_features, name);
+       }
 
        if (must_free)
                ha_free(&build_features);