]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: cli: improve forward compatibility for show fd
authorMaxime Henrion <mhenrion@haproxy.com>
Fri, 8 May 2026 14:30:30 +0000 (10:30 -0400)
committerOlivier Houchard <cognet@ci0.org>
Wed, 13 May 2026 08:33:20 +0000 (10:33 +0200)
The "<tgid>/" and "/" wildcard forms previously produced no output.
This isn't a bug since they are new, but a script written for future
versions (where the slash form will gain per-thread-group semantics)
would not work the same on 3.4. Make them produce output by dropping
the redundant ctx->fd = -1 wildcard sentinel; also tighten tgid
validation to reject values <= 0.

src/cli.c

index 8e96b4cd36b465a715961383fd73be86e4cb3df2..8210985e4166fb38b6bb0a527f5e77503416330b 100644 (file)
--- a/src/cli.c
+++ b/src/cli.c
@@ -1879,28 +1879,26 @@ static int cli_parse_show_fd(char **args, char *payload, struct appctx *appctx,
                        /* We allow the forms "<tgid>/" and "/<fd>" where the missing
                         * value is considered a wildcard. So the first form means
                         * "show me all the fds belonging to <tgid>", while the second
-                        * one means "show the fd <fd> for each thread group".
+                        * one means "show the fd <fd> for each thread group". Note
+                        * that the tgid is parsed but ignored for now - this code
+                        * will require changes once we split fd tables.
                         */
-                       if (c == args[2])
+                       if (c == args[2]) {
                                ctx->tgid = -1;
-                       else
+                       } else {
                                ctx->tgid = atoi(args[2]);
-                       if (ctx->tgid > MAX_TGROUPS)
-                               return cli_err(appctx, "Invalid TGID.\n");
+                               if (ctx->tgid <= 0 || ctx->tgid > MAX_TGROUPS)
+                                       return cli_err(appctx, "Invalid TGID.\n");
+                       }
                        c++;
-                       if (!*c)
-                               ctx->fd = -1;
-                       else
+                       if (*c) {
                                ctx->fd = atoi(c);
+                               ctx->show_one = 1;
+                       }
                } else {
                        ctx->fd = atoi(args[2]);
-               }
-
-               /* This will need to change when we implement split fd tables. We
-                * completely ignore the tgid for now.
-                */
-               if (ctx->fd != -1)
                        ctx->show_one = 1;
+               }
        }
 
        return 0;