]> git.kaiwu.me - haproxy.git/commitdiff
MINOR: cli: allow specifying a tgid with show fd
authorMaxime Henrion <mhenrion@haproxy.com>
Mon, 27 Apr 2026 13:26:55 +0000 (09:26 -0400)
committerOlivier Houchard <cognet@ci0.org>
Thu, 7 May 2026 14:02:37 +0000 (16:02 +0200)
This will become useful when we implement using unshare() to split fd
tables per thread group. For now, the tgid is parsed but completely
ignored.

src/cli.c

index cab99aa33726bb09f4cddde93bf9f87f2b1172ea..55cd8dab84b2a26a4977792b35f0132acbf23d12 100644 (file)
--- a/src/cli.c
+++ b/src/cli.c
@@ -106,7 +106,8 @@ struct show_env_ctx {
 #define CLI_SHOWFD_F_ANY 0x0000003f   /* any type          */
 
 struct show_fd_ctx {
-       int fd;          /* first FD to show */
+       int fd;          /* first FD to show, -1=wildcard */
+       int tgid;        /* 0=unspecified, -1=wildcard, >0=specific tgid */
        int show_one;    /* stop after showing one FD */
        uint show_mask;  /* CLI_SHOWFD_F_xxx */
 };
@@ -1873,8 +1874,33 @@ static int cli_parse_show_fd(char **args, char *payload, struct appctx *appctx,
                ctx->show_mask = CLI_SHOWFD_F_ANY;
 
        if (*args[arg]) {
-               ctx->fd = atoi(args[2]);
-               ctx->show_one = 1;
+               c = strchr(args[2], '/');
+               if (c) {
+                       /* 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".
+                        */
+                       if (c == args[2])
+                               ctx->tgid = -1;
+                       else
+                               ctx->tgid = atoi(args[2]);
+                       if (ctx->tgid > MAX_TGROUPS)
+                               return cli_err(appctx, "Invalid TGID.\n");
+                       c++;
+                       if (!*c)
+                               ctx->fd = -1;
+                       else
+                               ctx->fd = atoi(c);
+               } 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;