]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: cli: implement execution context for manually registered keywords
authorWilly Tarreau <w@1wt.eu>
Thu, 12 Mar 2026 08:37:15 +0000 (09:37 +0100)
committerWilly Tarreau <w@1wt.eu>
Thu, 12 Mar 2026 17:06:38 +0000 (18:06 +0100)
Keywords registered out of an initcall will have a TH_EX_CTX_CLI_KWL
execution context pointing to the keyword list. The report will indicate
the 5 first words of the first command of the list, e.g.:

     exec_ctx: cli kwl starting with 'debug counters   '

This should also work for CLI keywords registered in Lua.

include/haproxy/tinfo-t.h
src/cli.c
src/tools.c

index a17527e79aa5d50b3b46c07d09f1682b7f40826c..031b491d8d804e5667aafb20fd9783b68dbe651f 100644 (file)
@@ -89,6 +89,7 @@ enum thread_exec_ctx_type {
        TH_EX_CTX_MUX,                      /* mux whose mux_ops is in .mux_ops */
        TH_EX_CTX_TASK,                     /* task or tasklet whose function is in .task */
        TH_EX_CTX_APPLET,                   /* applet whose applet is in .applet */
+       TH_EX_CTX_CLI_KWL,                  /* CLI keyword list, using .cli_kwl */
 };
 
 struct thread_exec_ctx {
@@ -105,6 +106,7 @@ struct thread_exec_ctx {
                const struct mux_ops *mux_ops;  /* used with TH_EX_CTX_MUX */
                const struct task *(*task)(struct task *, void *, unsigned int); /* used with TH_EX_CTX_TASK */
                const struct applet *applet;  /* used with TH_EX_CTX_APPLET */
+               const struct cli_kw_list *cli_kwl; /* used with TH_EX_CTX_CLI_KWL */
        };
 };
 
index a289f1d425c6889ea60089ee661ad5931c080b8c..88883b916d379a4e7b521e7539c1c4273df96426 100644 (file)
--- a/src/cli.c
+++ b/src/cli.c
@@ -410,6 +410,9 @@ void cli_register_kw(struct cli_kw_list *kw_list)
                if (caller_initcall) {
                        kw->exec_ctx.type = TH_EX_CTX_INITCALL;
                        kw->exec_ctx.initcall = caller_initcall;
+               } else {
+                       kw->exec_ctx.type = TH_EX_CTX_CLI_KWL;
+                       kw->exec_ctx.cli_kwl = kw_list;
                }
        }
        LIST_APPEND(&cli_keywords.list, &kw_list->list);
index 08dd480746e53cf8bc79d17b0d269be65f31bea2..112b57e82148ef8176195ec8b2d17ef402c3bb64 100644 (file)
@@ -66,6 +66,7 @@ extern void *__elf_aux_vector;
 #include <haproxy/api.h>
 #include <haproxy/applet.h>
 #include <haproxy/chunk.h>
+#include <haproxy/cli-t.h>
 #include <haproxy/compiler.h>
 #include <haproxy/dgram.h>
 #include <haproxy/global.h>
@@ -7555,6 +7556,14 @@ void chunk_append_thread_ctx(struct buffer *output, const struct thread_exec_ctx
        case TH_EX_CTX_APPLET:
                chunk_appendf(output,"applet '%s'", ctx->applet->name);
                break;
+       case TH_EX_CTX_CLI_KWL:
+               chunk_appendf(output,"cli kwl starting with '%s %s %s %s %s'",
+                             ctx->cli_kwl->kw[0].str_kw[0],
+                             ctx->cli_kwl->kw[0].str_kw[1] ? ctx->cli_kwl->kw[0].str_kw[1] : "",
+                             ctx->cli_kwl->kw[0].str_kw[2] ? ctx->cli_kwl->kw[0].str_kw[2] : "",
+                             ctx->cli_kwl->kw[0].str_kw[3] ? ctx->cli_kwl->kw[0].str_kw[3] : "",
+                             ctx->cli_kwl->kw[0].str_kw[4] ? ctx->cli_kwl->kw[0].str_kw[4] : "");
+               break;
        default:
                chunk_appendf(output,"other ctx %p", ctx->pointer);
                break;