]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
REORG: cli: move 'show backend' to proxy.c
authorWilliam Lallemand <wlallemand@haproxy.com>
Tue, 22 Nov 2016 11:34:16 +0000 (12:34 +0100)
committerWilly Tarreau <w@1wt.eu>
Thu, 24 Nov 2016 15:59:27 +0000 (16:59 +0100)
Move 'show backend' CLI functions to proxy.c and use the cli keyword API
to register it on the CLI.

include/types/cli.h
src/cli.c
src/proxy.c

index 72b2c2dac28080e00a91bc3758b2f3d0102b9ddc..5c703d4d18bdfbe3e876645dfc2fc16fd6569147 100644 (file)
@@ -116,7 +116,6 @@ enum {
        STAT_CLI_O_CLR,      /* clear tables */
        STAT_CLI_O_SET,      /* set entries in tables */
        STAT_CLI_O_STAT,     /* dump stats */
-       STAT_CLI_O_BACKEND,  /* dump backend list */
        STAT_CLI_O_ENV,      /* dump environment */
        STAT_CLI_O_CUSTOM,   /* custom callback pointer */
 };
index 11f7e445d43a6605a80596617e30cb91a616346c..efceb72d194502fe0b7688ced2049d9438e4f77a 100644 (file)
--- a/src/cli.c
+++ b/src/cli.c
@@ -133,7 +133,6 @@ const char *info_field_names[INF_TOTAL_FIELDS] = {
 /* one line of stats */
 static struct field info[INF_TOTAL_FIELDS];
 
-static int stats_dump_backend_to_buffer(struct stream_interface *si);
 static int stats_dump_env_to_buffer(struct stream_interface *si);
 static int stats_dump_info_to_buffer(struct stream_interface *si);
 static int stats_dump_errors_to_buffer(struct stream_interface *si);
@@ -149,7 +148,6 @@ static const char stats_sock_usage_msg[] =
        "  help           : this message\n"
        "  prompt         : toggle interactive mode with prompt\n"
        "  quit           : disconnect\n"
-       "  show backend   : list backends in the current running config\n"
        "  show env [var] : dump environment variables known to the process\n"
        "  show info      : report information about the running process\n"
        "  show stat      : report counters for each proxy and server\n"
@@ -1053,12 +1051,7 @@ static int stats_sock_parse_request(struct stream_interface *si, char *line)
                        }
                }
        } else if (strcmp(args[0], "show") == 0) {
-               if (strcmp(args[1], "backend") == 0) {
-                       appctx->ctx.be.px = NULL;
-                       appctx->st2 = STAT_ST_INIT;
-                       appctx->st0 = STAT_CLI_O_BACKEND;
-               }
-               else if (strcmp(args[1], "env") == 0) {
+               if (strcmp(args[1], "env") == 0) {
                        extern char **environ;
 
                        if (strm_li(s)->bind_conf->level < ACCESS_LVL_OPER) {
@@ -1882,10 +1875,6 @@ static void cli_io_handler(struct appctx *appctx)
                                else
                                        si_applet_cant_put(si);
                                break;
-                       case STAT_CLI_O_BACKEND:
-                               if (stats_dump_backend_to_buffer(si))
-                                       appctx->st0 = STAT_CLI_PROMPT;
-                               break;
                        case STAT_CLI_O_INFO:
                                if (stats_dump_info_to_buffer(si))
                                        appctx->st0 = STAT_CLI_PROMPT;
@@ -2137,44 +2126,6 @@ static int stats_dump_info_to_buffer(struct stream_interface *si)
        return 1;
 }
 
-/* Parses backend list and simply report backend names */
-static int stats_dump_backend_to_buffer(struct stream_interface *si)
-{
-       struct appctx *appctx = __objt_appctx(si->end);
-       extern struct proxy *proxy;
-       struct proxy *curproxy;
-
-       chunk_reset(&trash);
-
-       if (!appctx->ctx.be.px) {
-               chunk_printf(&trash, "# name\n");
-               if (bi_putchk(si_ic(si), &trash) == -1) {
-                       si_applet_cant_put(si);
-                       return 0;
-               }
-               appctx->ctx.be.px = proxy;
-       }
-
-       for (; appctx->ctx.be.px != NULL; appctx->ctx.be.px = curproxy->next) {
-               curproxy = appctx->ctx.be.px;
-
-               /* looking for backends only */
-               if (!(curproxy->cap & PR_CAP_BE))
-                       continue;
-
-               /* we don't want to list a backend which is bound to this process */
-               if (curproxy->bind_proc && !(curproxy->bind_proc & (1UL << (relative_pid - 1))))
-                       continue;
-
-               chunk_appendf(&trash, "%s\n", curproxy->id);
-               if (bi_putchk(si_ic(si), &trash) == -1) {
-                       si_applet_cant_put(si);
-                       return 0;
-               }
-       }
-
-       return 1;
-}
 
 /* This is called when the stream interface is closed. For instance, upon an
  * external abort, we won't call the i/o handler anymore so we may need to
index 5313333c1a4ae5a706aa957f36627d2b7004ef1d..45a3db09ea7eb4e2ce3bd9db528ed8e36ad48c29 100644 (file)
@@ -1374,10 +1374,55 @@ static int cli_io_handler_servers_state(struct appctx *appctx)
        return 1;
 }
 
+static int cli_parse_show_backend(char **args, struct appctx *appctx, void *private)
+{
+       appctx->ctx.be.px = NULL;
+       return 0;
+}
+
+/* Parses backend list and simply report backend names */
+static int cli_io_handler_show_backend(struct appctx *appctx)
+{
+       extern struct proxy *proxy;
+       struct stream_interface *si = appctx->owner;
+       struct proxy *curproxy;
+
+       chunk_reset(&trash);
+
+       if (!appctx->ctx.be.px) {
+               chunk_printf(&trash, "# name\n");
+               if (bi_putchk(si_ic(si), &trash) == -1) {
+                       si_applet_cant_put(si);
+                       return 0;
+               }
+               appctx->ctx.be.px = proxy;
+       }
+
+       for (; appctx->ctx.be.px != NULL; appctx->ctx.be.px = curproxy->next) {
+               curproxy = appctx->ctx.be.px;
+
+               /* looking for backends only */
+               if (!(curproxy->cap & PR_CAP_BE))
+                       continue;
+
+               /* we don't want to list a backend which is bound to this process */
+               if (curproxy->bind_proc && !(curproxy->bind_proc & (1UL << (relative_pid - 1))))
+                       continue;
+
+               chunk_appendf(&trash, "%s\n", curproxy->id);
+               if (bi_putchk(si_ic(si), &trash) == -1) {
+                       si_applet_cant_put(si);
+                       return 0;
+               }
+       }
+
+       return 1;
+}
 
 /* register cli keywords */
 static struct cli_kw_list cli_kws = {{ },{
        { { "show","servers", "state",  NULL }, "show servers state [id]: dump volatile server information (for backend <id>)", cli_parse_show_servers, cli_io_handler_servers_state },
+       { { "show", "backend", NULL }, "show backend   : list backends in the current running config", cli_parse_show_backend, cli_io_handler_show_backend },
        {{},}
 }};