From: Willy Tarreau Date: Wed, 30 Nov 2022 15:50:48 +0000 (+0100) Subject: MINOR: debug: improve error handling on the memstats command parser X-Git-Tag: v2.7.0~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=334d091b759b74bc45ec2c84de4f1ee40b3ed6ec;p=thirdparty%2Fhaproxy.git MINOR: debug: improve error handling on the memstats command parser "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. --- diff --git a/src/debug.c b/src/debug.c index 1c9f43b868..88cd2fead8 100644 --- a/src/debug.c +++ b/src/debug.c @@ -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;