]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: proxy: register a post-section cleanup function
authorWilly Tarreau <w@1wt.eu>
Fri, 11 Jul 2025 06:58:48 +0000 (08:58 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 15 Jul 2025 08:40:17 +0000 (10:40 +0200)
For listen/frontend/backend, we now want to be able to clean up the
default-server directive that's no longer used past the end of the
section. For this we register a post-section function and perform the
cleanup there.

src/proxy.c

index c6f17eb19c8e6d5f8d34a60aecf4e858d4d2338c..680e046eb39321a16751e2b66a8df053198b7a41 100644 (file)
@@ -2818,6 +2818,30 @@ void proxy_adjust_all_maxconn()
        }
 }
 
+/* releases what's no longer needed after a proxy section covering <curproxy>.
+ * Returns an error code made of ERR_*, or 0 on success.
+ */
+static int post_section_px_cleanup()
+{
+       if ((curproxy->cap & PR_CAP_LISTEN) && !(curproxy->cap & PR_CAP_DEF)) {
+               /* This is a regular proxy (not defaults). It doesn't need
+                * to keep a default-server section if it still had one. We
+                * want to keep it for defaults however, obviously.
+                */
+
+               if (curproxy->defsrv) {
+                       ha_free((char **)&curproxy->defsrv->conf.file);
+                       ha_free(&curproxy->defsrv);
+               }
+       }
+       return 0;
+}
+
+REGISTER_CONFIG_POST_SECTION("frontend", post_section_px_cleanup);
+REGISTER_CONFIG_POST_SECTION("backend",  post_section_px_cleanup);
+REGISTER_CONFIG_POST_SECTION("listen",   post_section_px_cleanup);
+REGISTER_CONFIG_POST_SECTION("defaults", post_section_px_cleanup);
+
 /* Config keywords below */
 
 static struct cfg_kw_list cfg_kws = {ILH, {