]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: debug: improve error handling on the memstats command parser
authorWilly Tarreau <w@1wt.eu>
Wed, 30 Nov 2022 15:50:48 +0000 (16:50 +0100)
committerWilly Tarreau <w@1wt.eu>
Wed, 30 Nov 2022 16:24:29 +0000 (17:24 +0100)
"debug dev memstats" supports various options but silently ignores the
unknown ones. Let's make sure it returns indications about what it
expects, as the help message is quite limited otherwise.

src/debug.c

index 1c9f43b8684e5ef3bdf288a07220bfdfc484a0ea..88cd2fead84d3c67a7ebd149dc3cc470a8037051 100644 (file)
@@ -1245,6 +1245,7 @@ struct dev_mem_ctx {
 static int debug_parse_cli_memstats(char **args, char *payload, struct appctx *appctx, void *private)
 {
        struct dev_mem_ctx *ctx = applet_reserve_svcctx(appctx, sizeof(*ctx));
+       int arg;
 
        extern __attribute__((__weak__)) struct mem_stats __start_mem_stats;
        extern __attribute__((__weak__)) struct mem_stats __stop_mem_stats;
@@ -1252,22 +1253,27 @@ static int debug_parse_cli_memstats(char **args, char *payload, struct appctx *a
        if (!cli_has_level(appctx, ACCESS_LVL_OPER))
                return 1;
 
-       if (strcmp(args[3], "reset") == 0) {
-               struct mem_stats *ptr;
+       for (arg = 3; *args[arg]; arg++) {
+               if (strcmp(args[arg], "reset") == 0) {
+                       struct mem_stats *ptr;
 
-               if (!cli_has_level(appctx, ACCESS_LVL_ADMIN))
-                       return 1;
+                       if (!cli_has_level(appctx, ACCESS_LVL_ADMIN))
+                               return 1;
 
-               for (ptr = &__start_mem_stats; ptr < &__stop_mem_stats; ptr++) {
-                       _HA_ATOMIC_STORE(&ptr->calls, 0);
-                       _HA_ATOMIC_STORE(&ptr->size, 0);
+                       for (ptr = &__start_mem_stats; ptr < &__stop_mem_stats; ptr++) {
+                               _HA_ATOMIC_STORE(&ptr->calls, 0);
+                               _HA_ATOMIC_STORE(&ptr->size, 0);
+                       }
+                       return 1;
                }
-               return 1;
+               else if (strcmp(args[arg], "all") == 0) {
+                       ctx->show_all = 1;
+                       continue;
+               }
+               else
+                       return cli_err(appctx, "Expects either 'reset' or 'all'.\n");
        }
 
-       if (strcmp(args[3], "all") == 0)
-               ctx->show_all = 1;
-
        /* otherwise proceed with the dump from p0 to p1 */
        ctx->start = &__start_mem_stats;
        ctx->stop  = &__stop_mem_stats;