]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: cli: display failure reason on wait command
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Tue, 19 Aug 2025 15:20:51 +0000 (17:20 +0200)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Thu, 28 Aug 2025 12:52:29 +0000 (14:52 +0200)
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

index 027cab1e42944df4642bad02d3e5f1e0b7f9e9c4..ba0b3ab7b4a3ac070df7181d1fa039892b938dec 100644 (file)
--- 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 */