Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI improvements #3991

Draft
wants to merge 15 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions bin/varnishd/cache/cache_acceptor.c
Original file line number Diff line number Diff line change
Expand Up @@ -752,8 +752,8 @@ ccf_listen_address(struct cli *cli, const char * const *av, void *priv)
/*--------------------------------------------------------------------*/

static struct cli_proto vca_cmds[] = {
{ CLICMD_SERVER_START, "", ccf_start },
{ CLICMD_DEBUG_LISTEN_ADDRESS, "d", ccf_listen_address },
{ CLICMD_SERVER_START, ccf_start },
{ CLICMD_DEBUG_LISTEN_ADDRESS, ccf_listen_address },
{ NULL }
};

Expand Down
5 changes: 2 additions & 3 deletions bin/varnishd/cache/cache_ban.c
Original file line number Diff line number Diff line change
Expand Up @@ -944,9 +944,8 @@ ccf_ban_list(struct cli *cli, const char * const *av, void *priv)
}

static struct cli_proto ban_cmds[] = {
{ CLICMD_BAN, "", ccf_ban },
{ CLICMD_BAN_LIST, "", ccf_ban_list,
ccf_ban_list },
{ CLICMD_BAN, ccf_ban },
{ CLICMD_BAN_LIST, ccf_ban_list, ccf_ban_list },
{ NULL }
};

Expand Down
41 changes: 27 additions & 14 deletions bin/varnishd/cache/cache_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
#include "vcli_serve.h"

pthread_t cli_thread;
static struct lock cli_mtx;
static int add_check;
static struct VCLS *cache_cls;

Expand All @@ -65,29 +64,44 @@ CLI_AddFuncs(struct cli_proto *p)
{

AZ(add_check);
Lck_Lock(&cli_mtx);
VCLS_AddFunc(cache_cls, 0, p);
Lck_Unlock(&cli_mtx);
VCLS_AddFunc(cache_cls, p);
}

static void
cli_cb_before(const struct cli *cli)
cli_cb_before(const struct cli *cli, struct cli_proto *clp, const char * const *av)
{

ASSERT_CLI();
(void)av;

if (clp != NULL &&
VCLS_IsSensitive(clp->desc, DO_DEBUG(DBG_CLI_SHOW_SENSITIVE))) {
VSB_clear(cli->cmd);
if (clp->logfunc != NULL)
clp->logfunc(cli, av, cli->cmd);
else
VSB_printf(cli->cmd, "%s (hidden)", av[1]);
AZ(VSB_finish(cli->cmd));
}
VSL(SLT_CLI, NO_VXID, "Rd %s", VSB_data(cli->cmd));
Lck_Lock(&cli_mtx);
VCL_Poll();
}

static void
cli_cb_after(const struct cli *cli)
cli_cb_after(const struct cli *cli, struct cli_proto *clp, const char * const *av)
{

ASSERT_CLI();
Lck_Unlock(&cli_mtx);
VSL(SLT_CLI, NO_VXID, "Wr %03u %zd %s",
cli->result, VSB_len(cli->sb), VSB_data(cli->sb));
(void)av;
const char *h = "(hidden)";

if (clp != NULL &&
VCLS_IsSensitive(clp->desc, DO_DEBUG(DBG_CLI_SHOW_SENSITIVE))) {
VSL(SLT_CLI, NO_VXID, "Wr %03u %zd %s",
cli->result, strlen(h), h);
} else {
VSL(SLT_CLI, NO_VXID, "Wr %03u %zd %s",
cli->result, VSB_len(cli->sb), VSB_data(cli->sb));
}
}

void
Expand Down Expand Up @@ -115,8 +129,8 @@ CLI_Run(void)
/*--------------------------------------------------------------------*/

static struct cli_proto cli_cmds[] = {
{ CLICMD_PING, "i", VCLS_func_ping, VCLS_func_ping_json },
{ CLICMD_HELP, "i", VCLS_func_help, VCLS_func_help_json },
{ CLICMD_PING, VCLS_func_ping, VCLS_func_ping_json },
{ CLICMD_HELP, VCLS_func_help, VCLS_func_help_json },
{ NULL }
};

Expand All @@ -128,7 +142,6 @@ void
CLI_Init(void)
{

Lck_New(&cli_mtx, lck_cli);
cli_thread = pthread_self();

cache_cls = VCLS_New(heritage.cls);
Expand Down
5 changes: 2 additions & 3 deletions bin/varnishd/cache/cache_director.c
Original file line number Diff line number Diff line change
Expand Up @@ -518,9 +518,8 @@ cli_backend_set_health(struct cli *cli, const char * const *av, void *priv)
/*---------------------------------------------------------------------*/

static struct cli_proto backend_cmds[] = {
{ CLICMD_BACKEND_LIST, "",
cli_backend_list, cli_backend_list },
{ CLICMD_BACKEND_SET_HEALTH, "", cli_backend_set_health },
{ CLICMD_BACKEND_LIST, cli_backend_list, cli_backend_list },
{ CLICMD_BACKEND_SET_HEALTH, cli_backend_set_health },
{ NULL }
};

Expand Down
2 changes: 1 addition & 1 deletion bin/varnishd/cache/cache_fetch_proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ debug_fragfetch(struct cli *cli, const char * const *av, void *priv)
}

static struct cli_proto debug_cmds[] = {
{ CLICMD_DEBUG_FRAGFETCH, "d", debug_fragfetch },
{ CLICMD_DEBUG_FRAGFETCH, debug_fragfetch },
{ NULL }
};

Expand Down
39 changes: 36 additions & 3 deletions bin/varnishd/cache/cache_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -261,10 +261,43 @@ cli_debug_srandom(struct cli *cli, const char * const *av, void *priv)
VRND_SeedTestable(seed);
}

static void v_matchproto_(cli_func_t)
cli_debug_sensitive(struct cli *cli, const char * const *av, void *priv)
{

(void)priv;
(void)av;
VCLI_Out(cli, "This should be logged nowhere");
}

static void v_matchproto_(cmd_log_func_t)
cli_debug_sensitive_log(const struct cli* cli, const char * const *av, struct vsb *vsb)
{

(void)cli;

AN(av);
AN(vsb);

VSB_printf(vsb, "%s %s XXXXX", av[1]!=NULL ? av[1] : "(null)",
av[2] != NULL ? av[2] : "(null)");
}

static void v_matchproto_(cli_func_t)
cli_debug_internal(struct cli *cli, const char * const *av, void *priv)
{

(void)priv;
(void)av;
VCLI_Out(cli, "This is an internal command");
}

static struct cli_proto debug_cmds[] = {
{ CLICMD_DEBUG_XID, "d", cli_debug_xid },
{ CLICMD_DEBUG_SHUTDOWN_DELAY, "d", cli_debug_shutdown_delay },
{ CLICMD_DEBUG_SRANDOM, "d", cli_debug_srandom },
{ CLICMD_DEBUG_XID, cli_debug_xid },
{ CLICMD_DEBUG_SHUTDOWN_DELAY, cli_debug_shutdown_delay },
{ CLICMD_DEBUG_SRANDOM, cli_debug_srandom },
{ CLICMD_DEBUG_SENSITIVE, cli_debug_sensitive, NULL, cli_debug_sensitive_log},
{ CLICMD_DEBUG_CLD_INTERNAL, cli_debug_internal },
{ NULL }
};

Expand Down
2 changes: 1 addition & 1 deletion bin/varnishd/cache/cache_panic.c
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,7 @@ ccf_panic(struct cli *cli, const char * const *av, void *priv)
/*--------------------------------------------------------------------*/

static struct cli_proto debug_cmds[] = {
{ CLICMD_DEBUG_PANIC_WORKER, "d", ccf_panic },
{ CLICMD_DEBUG_PANIC_WORKER, ccf_panic },
{ NULL }
};

Expand Down
14 changes: 7 additions & 7 deletions bin/varnishd/cache/cache_vcl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1005,13 +1005,13 @@ vcl_cli_show(struct cli *cli, const char * const *av, void *priv)
/*--------------------------------------------------------------------*/

static struct cli_proto vcl_cmds[] = {
{ CLICMD_VCL_LOAD, "", vcl_cli_load },
{ CLICMD_VCL_LIST, "", vcl_cli_list, vcl_cli_list_json },
{ CLICMD_VCL_STATE, "", vcl_cli_state },
{ CLICMD_VCL_DISCARD, "", vcl_cli_discard },
{ CLICMD_VCL_USE, "", vcl_cli_use },
{ CLICMD_VCL_SHOW, "", vcl_cli_show },
{ CLICMD_VCL_LABEL, "", vcl_cli_label },
{ CLICMD_VCL_LOAD, vcl_cli_load },
{ CLICMD_VCL_LIST, vcl_cli_list, vcl_cli_list_json },
{ CLICMD_VCL_STATE, vcl_cli_state },
{ CLICMD_VCL_DISCARD, vcl_cli_discard },
{ CLICMD_VCL_USE, vcl_cli_use },
{ CLICMD_VCL_SHOW, vcl_cli_show },
{ CLICMD_VCL_LABEL, vcl_cli_label },
{ NULL }
};

Expand Down
2 changes: 1 addition & 1 deletion bin/varnishd/cache/cache_vrt_vmod.c
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ ccf_debug_vmod(struct cli *cli, const char * const *av, void *priv)
}

static struct cli_proto vcl_cmds[] = {
{ CLICMD_DEBUG_VMOD, "d", ccf_debug_vmod },
{ CLICMD_DEBUG_VMOD, ccf_debug_vmod },
{ NULL }
};

Expand Down
2 changes: 1 addition & 1 deletion bin/varnishd/cache/cache_wrk.c
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ debug_reqpoolfail(struct cli *cli, const char * const *av, void *priv)
}

static struct cli_proto debug_cmds[] = {
{ CLICMD_DEBUG_REQPOOLFAIL, "d", debug_reqpoolfail },
{ CLICMD_DEBUG_REQPOOLFAIL, debug_reqpoolfail },
{ NULL }
};

Expand Down
2 changes: 0 additions & 2 deletions bin/varnishd/mgt/mgt.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,6 @@ void mgt_cli_secret(const char *S_arg);
void mgt_cli_close_all(void);
void mgt_DumpRstCli(void);
void mgt_cli_init_cls(void);
#define MCF_NOAUTH 0 /* NB: zero disables here-documents */
#define MCF_AUTH 16

/* mgt_jail.c */

Expand Down
14 changes: 7 additions & 7 deletions bin/varnishd/mgt/mgt_child.c
Original file line number Diff line number Diff line change
Expand Up @@ -800,14 +800,14 @@ mch_cli_server_status_json(struct cli *cli, const char * const *av, void *priv)
}

static struct cli_proto cli_mch[] = {
{ CLICMD_SERVER_STATUS, "", mch_cli_server_status,
{ CLICMD_SERVER_STATUS, mch_cli_server_status,
mch_cli_server_status_json },
{ CLICMD_SERVER_START, "", mch_cli_server_start },
{ CLICMD_SERVER_STOP, "", mch_cli_server_stop },
{ CLICMD_PANIC_SHOW, "", mch_cli_panic_show,
{ CLICMD_SERVER_START, mch_cli_server_start },
{ CLICMD_SERVER_STOP, mch_cli_server_stop },
{ CLICMD_PANIC_SHOW, mch_cli_panic_show,
mch_cli_panic_show_json },
{ CLICMD_PANIC_CLEAR, "", mch_cli_panic_clear },
{ CLICMD_PID, "", mch_pid, mch_pid_json },
{ CLICMD_PANIC_CLEAR, mch_cli_panic_clear },
{ CLICMD_PID, mch_pid, mch_pid_json },
{ NULL }
};

Expand All @@ -821,5 +821,5 @@ void
MCH_Init(void)
{

VCLS_AddFunc(mgt_cls, MCF_AUTH, cli_mch);
VCLS_AddFunc(mgt_cls, cli_mch);
}
Loading