]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
CLEANUP: muxes: do not use a dynamic trash in list_mux_protos()
authorWilly Tarreau <w@1wt.eu>
Fri, 18 Feb 2022 10:07:40 +0000 (11:07 +0100)
committerWilly Tarreau <w@1wt.eu>
Wed, 23 Feb 2022 16:11:33 +0000 (17:11 +0100)
Let's not use a trash there anymore. The function is called at very
early boot (for "haproxy -vv"), and the need for a trash prevents the
arguments from being parsed earlier. Moreover, the function only uses
a FILE* on output with fprintf(), so there's not even any benefit in
using chunk_printf() on an intermediary variable, emitting the output
directly is both clearer and safer.

src/connection.c

index f0fb3d665f91d7efbdded0f2c7b120ff053b9650..76becfc2b2ad3a60dd69eeb940626eee6c1835c6 100644 (file)
@@ -1603,13 +1603,16 @@ int conn_recv_socks4_proxy_response(struct connection *conn)
        return 0;
 }
 
-/* Lists the known proto mux on <out> */
+/* Lists the known proto mux on <out>. This function is used by "haproxy -vv"
+ * and is suitable for early boot just after the "REGISTER" stage because it
+ * doesn't depend on anything to be already allocated.
+ */
 void list_mux_proto(FILE *out)
 {
        struct mux_proto_list *item;
-       struct buffer *chk = get_trash_chunk();
        struct ist proto;
        char *mode, *side;
+       int done;
 
        fprintf(out, "Available multiplexer protocols :\n"
                "(protocols marked as <default> cannot be specified using 'proto' keyword)\n");
@@ -1634,19 +1637,27 @@ void list_mux_proto(FILE *out)
                else
                        side = "NONE";
 
-               chunk_reset(chk);
+               fprintf(out, " %15s : mode=%-10s side=%-8s  mux=%-8s flags=",
+                       (proto.len ? proto.ptr : "<default>"), mode, side, item->mux->name);
+
+               done = 0;
+
+               /* note: the block below could be simplied using macros but for only
+                * 4 flags it's not worth it.
+                */
                if (item->mux->flags & MX_FL_HTX)
-                       chunk_strcpy(chk, "HTX");
+                       done |= fprintf(out, "%sHTX", done ? "|" : "");
+
                if (item->mux->flags & MX_FL_CLEAN_ABRT)
-                       chunk_appendf(chk, "%sCLEAN_ABRT", (b_data(chk) ? "|": ""));
+                       done |= fprintf(out, "%sCLEAN_ABRT", done ? "|" : "");
+
                if (item->mux->flags & MX_FL_HOL_RISK)
-                       chunk_appendf(chk, "%sHOL_RISK", (b_data(chk) ? "|": ""));
+                       done |= fprintf(out, "%sHOL_RISK", done ? "|" : "");
+
                if (item->mux->flags & MX_FL_NO_UPG)
-                       chunk_appendf(chk, "%sNO_UPG", (b_data(chk) ? "|": ""));
+                       done |= fprintf(out, "%sNO_UPG", done ? "|" : "");
 
-               fprintf(out, " %15s : mode=%-10s side=%-8s  mux=%-8s flags=%.*s\n",
-                       (proto.len ? proto.ptr : "<default>"), mode, side, item->mux->name,
-                       (int)b_data(chk), b_orig(chk));
+               fprintf(out, "\n");
        }
 }