]> git.kaiwu.me - haproxy.git/commitdiff
BUG/MINOR: init: fix missing error on no listener on config check
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Fri, 13 Nov 2026 10:42:29 +0000 (11:42 +0100)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Fri, 13 Nov 2026 10:53:31 +0000 (11:53 +0100)
Since the conversion of the list of proxies, sinks and logs from a plain
linked list to a full struct list type, config check would not report an
error anymore if no listener is present.

This is caused because iterations are now performed via
list_for_each_entry() without producing a final NULL iterator value. Fix
this by using a plain boolean set during the loop and check its value at
the end instead of inspecting the iterator itself.

This should fix github issue #3567.

No need to backport.

src/haproxy.c

index 50584f415d63e20aea442401a854b381eba571d3..931aaa66d4676b592c92195ee753db9864e28cce 100644 (file)
@@ -2399,6 +2399,7 @@ static void step_init_2(int argc, char** argv)
        if (global.mode & MODE_CHECK) {
                struct peers *pr;
                struct proxy *px;
+               int listener_found = 0;
 
                if (warned & WARN_ANY)
                        qfprintf(stdout, "Warnings were found.\n");
@@ -2408,19 +2409,23 @@ static void step_init_2(int argc, char** argv)
                                break;
 
                list_for_each_entry(px, &main_proxies, el) {
-                       if (!(px->flags & (PR_FL_DISABLED|PR_FL_STOPPED)) && px->li_all)
+                       if (!(px->flags & (PR_FL_DISABLED|PR_FL_STOPPED)) && px->li_all) {
+                               listener_found = 1;
                                break;
+                       }
                }
 
-               if (!px) {
+               if (!listener_found) {
                        /* We may only have log-forward section */
                        list_for_each_entry(px, &cfg_log_forward, el) {
-                               if (!(px->flags & (PR_FL_DISABLED|PR_FL_STOPPED)) && px->li_all)
+                               if (!(px->flags & (PR_FL_DISABLED|PR_FL_STOPPED)) && px->li_all) {
+                                       listener_found = 1;
                                        break;
+                               }
                        }
                }
 
-               if (pr || px) {
+               if (pr || listener_found) {
                        /* At least one peer or one listener has been found */
                        if (global.mode & MODE_VERBOSE)
                                qfprintf(stdout, "Configuration file is valid\n");