]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: server: clear prefix on stderr logs after add server
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Thu, 10 Nov 2022 14:16:49 +0000 (15:16 +0100)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Thu, 10 Nov 2022 15:42:47 +0000 (16:42 +0100)
cli_parse_add_server() is the CLI handler for 'add server' command. This
functions uses usermsgs_ctx to retrieve logs messages from internal
ha_alert() calls and display it at the end of the handler.

At the beginning of the handler, stderr prefix is defined to "CLI" via
usermsgs_clr() function. However, this is not resetted at the end. This
causes inconsistency for stderr output :
1. each ha_alert() invocation will reuse "CLI" prefix if 'add server'
   command was executed before, even in non-CLI context
2. usermsgs_ctx is thread local, so this is only true if this runs on
   the same thread as 'add server' handler.

To fix this, ensure that "CLI" prefix is now resetted after
cli_parse_add_server(). This is done thanks to the addition to
cli_umsg()/cli_umsgerr() functions.

This can be backported up to 2.5 if we prefer to ensure output
consistency at the risk of changing stderr behaviors in stable versions.
In this case, the previous commit should be backported before :
  MINOR: cli: define usermsgs print context

src/server.c

index 437f3c23ec3c367ab6b9a89faf17d0acee92aa90..3381c8ecad124dedb7f8fc86b4f80b58df46aa42 100644 (file)
@@ -4869,7 +4869,7 @@ static int cli_parse_add_server(char **args, char *payload, struct appctx *appct
        }
 
        ha_notice("New server registered.\n");
-       cli_msg(appctx, LOG_INFO, usermsgs_str());
+       cli_umsg(appctx, LOG_INFO);
 
        return 0;
 
@@ -4900,7 +4900,7 @@ out:
        thread_release();
 
        if (!usermsgs_empty())
-               cli_err(appctx, usermsgs_str());
+               cli_umsgerr(appctx);
 
        if (srv)
                srv_drop(srv);