]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
CLEANUP: debug/cli: make "debug dev fd" not use ctx.cli anymore
authorWilly Tarreau <w@1wt.eu>
Thu, 5 May 2022 12:26:28 +0000 (14:26 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 6 May 2022 16:13:36 +0000 (18:13 +0200)
The command only requires to store an int, but it will be useful later
to have a struct to pass extra info such as an "all" flag to dump all
FDs. The new context is now a struct dev_fd_ctx stored in svcctx.

src/debug.c

index b8743377bfb661bec26845d5e194273c12b2b840..149c21984eaf550eb86211998a9e2debc7e1a20e 100644 (file)
@@ -1017,25 +1017,33 @@ static int debug_parse_cli_sched(char **args, char *payload, struct appctx *appc
        return cli_err(appctx, "Not enough memory");
 }
 
+/* CLI state for "debug dev fd" */
+struct dev_fd_ctx {
+       int start_fd;
+};
+
 /* CLI parser for the "debug dev fd" command. The current FD to restart from is
- * stored in i0.
+ * stored in a struct dev_fd_ctx pointed to by svcctx.
  */
 static int debug_parse_cli_fd(char **args, char *payload, struct appctx *appctx, void *private)
 {
+       struct dev_fd_ctx *ctx = applet_reserve_svcctx(appctx, sizeof(*ctx));
+
        if (!cli_has_level(appctx, ACCESS_LVL_OPER))
                return 1;
 
        /* start at fd #0 */
-       appctx->ctx.cli.i0 = 0;
+       ctx->start_fd = 0;
        return 0;
 }
 
 /* CLI I/O handler for the "debug dev fd" command. Dumps all FDs that are
  * accessible from the process but not known from fdtab. The FD number to
- * restart from is stored in i0.
+ * restart from is stored in a struct dev_fd_ctx pointed to by svcctx.
  */
 static int debug_iohandler_fd(struct appctx *appctx)
 {
+       struct dev_fd_ctx *ctx = appctx->svcctx;
        struct conn_stream *cs = appctx->owner;
        struct sockaddr_storage sa;
        struct stat statbuf;
@@ -1055,7 +1063,7 @@ static int debug_iohandler_fd(struct appctx *appctx)
        /* we have two inner loops here, one for the proxy, the other one for
         * the buffer.
         */
-       for (fd = appctx->ctx.cli.i0; fd < global.maxsock; fd++) {
+       for (fd = ctx->start_fd; fd < global.maxsock; fd++) {
                /* check for FD's existence */
                ret1 = fcntl(fd, F_GETFD, 0);
                if (ret1 == -1)
@@ -1171,7 +1179,7 @@ static int debug_iohandler_fd(struct appctx *appctx)
 
                if (ci_putchk(cs_ic(cs), &trash) == -1) {
                        cs_rx_room_blk(cs);
-                       appctx->ctx.cli.i0 = fd;
+                       ctx->start_fd = fd;
                        ret = 0;
                        break;
                }