]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
CLEANUP: peers/cli: remove unneeded state STATE_INIT
authorWilly Tarreau <w@1wt.eu>
Tue, 3 May 2022 13:04:25 +0000 (15:04 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 6 May 2022 16:13:35 +0000 (18:13 +0200)
All the settings in this initial state are konwn at parsing time,
there's no need for an initial state to bootstrap other ones.

src/peers.c

index e8d5b4fd88488c9502fbd8881e85b953683ae318..34de1f60cf695d8223631d5ca44e1b4621ae907b 100644 (file)
@@ -3706,8 +3706,7 @@ struct show_peers_ctx {
        struct peer *peer;      /* "peer" being currently dumped. */
        int flags;              /* non-zero if "dict" dump requested */
        enum {
-               STATE_INIT = 0, /* initialization */
-               STATE_HEAD,     /* dump the section's header */
+               STATE_HEAD = 0, /* dump the section's header */
                STATE_PEER,     /* dump the whole peer */
                STATE_DONE,     /* finished */
        } state;                /* parser's state */
@@ -3743,6 +3742,8 @@ static int cli_parse_show_peers(char **args, char *payload, struct appctx *appct
                        return cli_err(appctx, "No such peers\n");
        }
 
+       /* where to start from */
+       ctx->peers = ctx->target ? ctx->target : cfg_peers;
        return 0;
 }
 
@@ -3943,26 +3944,14 @@ static int peers_dump_peer(struct buffer *msg, struct conn_stream *cs, struct pe
 static int cli_io_handler_show_peers(struct appctx *appctx)
 {
        struct show_peers_ctx *ctx = appctx->svcctx;
-       int show_all;
        int ret = 0, first_peers = 1;
 
        thread_isolate();
 
-       show_all = !ctx->target;
-
        chunk_reset(&trash);
 
        while (ctx->state != STATE_DONE) {
                switch (ctx->state) {
-               case STATE_INIT:
-                       if (show_all)
-                               ctx->peers = cfg_peers;
-                       else
-                               ctx->peers = ctx->target;
-
-                       ctx->state = STATE_HEAD;
-                       /* fall through */
-
                case STATE_HEAD:
                        if (!ctx->peers) {
                                /* No more peers list. */
@@ -3985,8 +3974,8 @@ static int cli_io_handler_show_peers(struct appctx *appctx)
                case STATE_PEER:
                        if (!ctx->peer) {
                                /* End of peer list */
-                               if (show_all)
-                                       ctx->state = STATE_HEAD;
+                               if (!ctx->target)
+                                       ctx->state = STATE_HEAD; // next one
                            else
                                        ctx->state = STATE_DONE;
                        }