]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
REORG: mworker/cli: move CLI functions to mworker.c
authorWilliam Lallemand <wlallemand@haproxy.com>
Mon, 1 Apr 2019 09:30:01 +0000 (11:30 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 1 Apr 2019 12:45:37 +0000 (14:45 +0200)
Move the CLI functions of the master worker to mworker.c

src/cli.c
src/mworker.c

index def5ebacc6780dee4723c78fbfd4f2c07c49c7ef..38c178dc24e8ba49e701ba36399760c227258973 100644 (file)
--- a/src/cli.c
+++ b/src/cli.c
@@ -1324,16 +1324,6 @@ static int cli_parse_set_lvl(char **args, char *payload, struct appctx *appctx,
        return 1;
 }
 
-/* reload the master process */
-static int cli_parse_reload(char **args, char *payload, struct appctx *appctx, void *private)
-{
-       if (!cli_has_level(appctx, ACCESS_LVL_OPER))
-               return 1;
-
-       mworker_reload();
-
-       return 1;
-}
 
 int cli_parse_default(char **args, char *payload, struct appctx *appctx, void *private)
 {
@@ -1461,66 +1451,6 @@ static int bind_parse_severity_output(char **args, int cur_arg, struct proxy *px
 }
 
 
- /*  Displays workers and processes  */
-static int cli_io_handler_show_proc(struct appctx *appctx)
-{
-       struct stream_interface *si = appctx->owner;
-       struct mworker_proc *child;
-       int old = 0;
-       int up = now.tv_sec - proc_self->timestamp;
-
-       if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW)))
-               return 1;
-
-       chunk_reset(&trash);
-
-       chunk_printf(&trash, "#%-14s %-15s %-15s %-15s %s\n", "<PID>", "<type>", "<relative PID>", "<reloads>", "<uptime>");
-       chunk_appendf(&trash, "%-15u %-15s %-15u %-15d %dd %02dh%02dm%02ds\n", getpid(), "master", 0, proc_self->reloads, up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60));
-
-       /* displays current processes */
-
-       chunk_appendf(&trash, "# workers\n");
-       list_for_each_entry(child, &proc_list, list) {
-               up = now.tv_sec - child->timestamp;
-
-               if (child->type != 'w')
-                       continue;
-
-               if (child->reloads > 0) {
-                       old++;
-                       continue;
-               }
-               chunk_appendf(&trash, "%-15u %-15s %-15u %-15d %dd %02dh%02dm%02ds\n", child->pid, "worker", child->relative_pid, child->reloads, up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60));
-       }
-
-       /* displays old processes */
-
-       if (old) {
-               char *msg = NULL;
-
-               chunk_appendf(&trash, "# old workers\n");
-               list_for_each_entry(child, &proc_list, list) {
-                       up = now.tv_sec - child->timestamp;
-
-                       if (child->type != 'w')
-                               continue;
-
-                       if (child->reloads > 0) {
-                               memprintf(&msg, "[was: %u]", child->relative_pid);
-                               chunk_appendf(&trash, "%-15u %-15s %-15s %-15d %dd %02dh%02dm%02ds\n", child->pid, "worker", msg, child->reloads, up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60));
-                       }
-               }
-               free(msg);
-       }
-
-       if (ci_putchk(si_ic(si), &trash) == -1) {
-               si_rx_room_blk(si);
-               return 0;
-       }
-
-       /* dump complete */
-       return 1;
-}
 
 /* Send all the bound sockets, always returns 1 */
 static int _getsocks(char **args, char *payload, struct appctx *appctx, void *private)
@@ -2615,9 +2545,6 @@ static struct applet cli_applet = {
 
 /* register cli keywords */
 static struct cli_kw_list cli_kws = {{ },{
-       { { "@<relative pid>", NULL }, "@<relative pid> : send a command to the <relative pid> process", NULL, cli_io_handler_show_proc, NULL, NULL, ACCESS_MASTER_ONLY},
-       { { "@!<pid>", NULL }, "@!<pid>        : send a command to the <pid> process", cli_parse_default, NULL, NULL, NULL, ACCESS_MASTER_ONLY},
-       { { "@master", NULL }, "@master        : send a command to the master process", cli_parse_default, NULL, NULL, NULL, ACCESS_MASTER_ONLY},
        { { "help", NULL }, NULL, cli_parse_simple, NULL },
        { { "prompt", NULL }, NULL, cli_parse_simple, NULL },
        { { "quit", NULL }, NULL, cli_parse_simple, NULL },
@@ -2630,10 +2557,8 @@ static struct cli_kw_list cli_kws = {{ },{
        { { "show", "cli", "level", NULL },    "show cli level   : display the level of the current CLI session", cli_parse_show_lvl, NULL, NULL, NULL, ACCESS_MASTER},
        { { "show", "fd", NULL }, "show fd [num] : dump list of file descriptors in use", cli_parse_show_fd, cli_io_handler_show_fd, NULL },
        { { "show", "activity", NULL }, "show activity : show per-thread activity stats (for support/developers)", cli_parse_default, cli_io_handler_show_activity, NULL },
-       { { "show", "proc", NULL }, "show proc      : show processes status", cli_parse_default, cli_io_handler_show_proc, NULL, NULL, ACCESS_MASTER_ONLY},
        { { "operator", NULL },  "operator       : lower the level of the current CLI session to operator", cli_parse_set_lvl, NULL, NULL, NULL, ACCESS_MASTER},
        { { "user", NULL },      "user           : lower the level of the current CLI session to user", cli_parse_set_lvl, NULL, NULL, NULL, ACCESS_MASTER},
-       { { "reload", NULL },    "reload         : reload haproxy", cli_parse_reload, NULL, NULL, NULL, ACCESS_MASTER_ONLY},
        { { "_getsocks", NULL }, NULL,  _getsocks, NULL },
        {{},}
 }};
index 0c4ae21b270110f5e1ef3cfbeca02a0a9cccc84e..d92358d33820880e2168afa2b078d787623667ce 100644 (file)
 #include <string.h>
 #include <sys/wait.h>
 
+#include <common/initcall.h>
 #include <common/mini-clist.h>
 
+#include <types/cli.h>
+#include <types/global.h>
+#include <types/peers.h>
+#include <types/signal.h>
+
+#include <proto/cli.h>
 #include <proto/fd.h>
 #include <proto/listener.h>
 #include <proto/log.h>
 #include <proto/mworker.h>
+#include <proto/proxy.h>
 #include <proto/signal.h>
+#include <proto/stream.h>
+#include <proto/stream_interface.h>
 
-#include <types/global.h>
-#include <types/peers.h>
-#include <proto/proxy.h>
-#include <types/signal.h>
 
 #if defined(USE_SYSTEMD)
 #include <systemd/sd-daemon.h>
@@ -374,3 +380,88 @@ void mworker_cleanlisteners()
                        curproxy->state = PR_STSTOPPED;
        }
 }
+
+/*  Displays workers and processes  */
+static int cli_io_handler_show_proc(struct appctx *appctx)
+{
+       struct stream_interface *si = appctx->owner;
+       struct mworker_proc *child;
+       int old = 0;
+       int up = now.tv_sec - proc_self->timestamp;
+
+       if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW)))
+               return 1;
+
+       chunk_reset(&trash);
+
+       chunk_printf(&trash, "#%-14s %-15s %-15s %-15s %s\n", "<PID>", "<type>", "<relative PID>", "<reloads>", "<uptime>");
+       chunk_appendf(&trash, "%-15u %-15s %-15u %-15d %dd %02dh%02dm%02ds\n", getpid(), "master", 0, proc_self->reloads, up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60));
+
+       /* displays current processes */
+
+       chunk_appendf(&trash, "# workers\n");
+       list_for_each_entry(child, &proc_list, list) {
+               up = now.tv_sec - child->timestamp;
+
+               if (child->type != 'w')
+                       continue;
+
+               if (child->reloads > 0) {
+                       old++;
+                       continue;
+               }
+               chunk_appendf(&trash, "%-15u %-15s %-15u %-15d %dd %02dh%02dm%02ds\n", child->pid, "worker", child->relative_pid, child->reloads, up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60));
+       }
+
+       /* displays old processes */
+
+       if (old) {
+               char *msg = NULL;
+
+               chunk_appendf(&trash, "# old workers\n");
+               list_for_each_entry(child, &proc_list, list) {
+                       up = now.tv_sec - child->timestamp;
+
+                       if (child->type != 'w')
+                               continue;
+
+                       if (child->reloads > 0) {
+                               memprintf(&msg, "[was: %u]", child->relative_pid);
+                               chunk_appendf(&trash, "%-15u %-15s %-15s %-15d %dd %02dh%02dm%02ds\n", child->pid, "worker", msg, child->reloads, up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60));
+                       }
+               }
+               free(msg);
+       }
+
+       if (ci_putchk(si_ic(si), &trash) == -1) {
+               si_rx_room_blk(si);
+               return 0;
+       }
+
+       /* dump complete */
+       return 1;
+}
+
+/* reload the master process */
+static int cli_parse_reload(char **args, char *payload, struct appctx *appctx, void *private)
+{
+       if (!cli_has_level(appctx, ACCESS_LVL_OPER))
+               return 1;
+
+       mworker_reload();
+
+       return 1;
+}
+
+
+/* register cli keywords */
+static struct cli_kw_list cli_kws = {{ },{
+       { { "@<relative pid>", NULL }, "@<relative pid> : send a command to the <relative pid> process", NULL, cli_io_handler_show_proc, NULL, NULL, ACCESS_MASTER_ONLY},
+       { { "@!<pid>", NULL }, "@!<pid>        : send a command to the <pid> process", cli_parse_default, NULL, NULL, NULL, ACCESS_MASTER_ONLY},
+       { { "@master", NULL }, "@master        : send a command to the master process", cli_parse_default, NULL, NULL, NULL, ACCESS_MASTER_ONLY},
+       { { "show", "proc", NULL }, "show proc      : show processes status", cli_parse_default, cli_io_handler_show_proc, NULL, NULL, ACCESS_MASTER_ONLY},
+       { { "reload", NULL },    "reload         : reload haproxy", cli_parse_reload, NULL, NULL, NULL, ACCESS_MASTER_ONLY},
+       {{},}
+}};
+
+INITCALL1(STG_REGISTER, cli_register_kw, &cli_kws);