From bce29bc7a491e26f73b412e328c38f9f21adcb61 Mon Sep 17 00:00:00 2001 From: Amaury Denoyelle Date: Tue, 19 Aug 2025 17:20:51 +0200 Subject: [PATCH] MINOR: cli: display failure reason on wait command wait CLI command can be used to wait until either a defined timeout or a specific condition is reached. So far, srv-removable is the only event supported. This is tested via srv_check_for_deletion(). This is implemented via srv_check_for_deletion(), which is able to report a message describing the reason if the condition is unmet. Previously, wait return a generic string, to specify if the condition is met, the timer has expired or an immediate error is encountered. In case of srv-removable, it did not report the real reason why a server could not be removed. This patch improves wait command with srv-removable. It now displays the last message returned by srv_check_for_deletion(), either on immediate error or on timeout. This is implemented by using dynamic string output with cli_dynmsg/dynerr() functions. --- src/cli.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/cli.c b/src/cli.c index 027cab1e4..ba0b3ab7b 100644 --- a/src/cli.c +++ b/src/cli.c @@ -2163,7 +2163,7 @@ static int cli_io_handler_wait(struct appctx *appctx) if (ctx->cond == CLI_WAIT_COND_SRV_UNUSED) { /* check if the server in args[0]/args[1] can be released now */ - ret = srv_check_for_deletion(ctx->args[0], ctx->args[1], NULL, NULL, NULL); + ret = srv_check_for_deletion(ctx->args[0], ctx->args[1], NULL, NULL, &ctx->msg); if (ret < 0) { /* unrecoverable failure */ @@ -2215,23 +2215,23 @@ static int cli_io_handler_wait(struct appctx *appctx) static void cli_release_wait(struct appctx *appctx) { struct cli_wait_ctx *ctx = appctx->svcctx; - const char *msg; + char *msg = NULL; int i; switch (ctx->error) { - case CLI_WAIT_ERR_EXP: msg = "Wait delay expired.\n"; break; - case CLI_WAIT_ERR_INTR: msg = "Interrupted.\n"; break; - case CLI_WAIT_ERR_FAIL: msg = ctx->msg ? ctx->msg : "Failed.\n"; break; - default: msg = "Done.\n"; break; + case CLI_WAIT_ERR_EXP: memprintf(&msg, "Wait delay expired. %s\n", ctx->msg); break; + case CLI_WAIT_ERR_INTR: memprintf(&msg, "Interrupted. %s\n", ctx->msg); break; + case CLI_WAIT_ERR_FAIL: memprintf(&msg, "Failed. %s\n", ctx->msg); break; + default: memprintf(&msg, "Done.\n"); break; } for (i = 0; i < sizeof(ctx->args) / sizeof(ctx->args[0]); i++) ha_free(&ctx->args[i]); if (ctx->error == CLI_WAIT_ERR_DONE) - cli_msg(appctx, LOG_INFO, msg); + cli_dynmsg(appctx, LOG_INFO, msg); else - cli_err(appctx, msg); + cli_dynerr(appctx, msg); } /* parse the "expose-fd" argument on the bind lines */