Commit 28dafefe authored by Tollef Fog Heen's avatar Tollef Fog Heen

Add panic.show and panic.clear CLI commands

panic.show shows the last panic from the child
panic.clear removes it.
parent 8ef6c175
/*-
* Copyright (c) 2006 Verdens Gang AS
* Copyright (c) 2006-2010 Redpill Linpro AS
* Copyright (c) 2011 Varnish Software AS
* All rights reserved.
*
* Author: Poul-Henning Kamp <phk@phk.freebsd.dk>
......
......@@ -91,6 +91,8 @@ static struct vev *ev_poker;
static struct vev *ev_listen;
static struct vlu *vlu;
static struct vsb *child_panic = NULL;
/*--------------------------------------------------------------------
* Track the highest file descriptor the parent knows is being used.
*
......@@ -433,6 +435,31 @@ mgt_report_panic(pid_t r)
(intmax_t)r, vsm_head->panicstr);
}
static void
mgt_save_panic(void)
{
char time_str[30];
if (vsm_head->panicstr[0] == '\0')
return;
if (child_panic)
vsb_delete(child_panic);
child_panic = vsb_newauto();
XXXAN(child_panic);
TIM_format(TIM_real(), time_str);
vsb_printf(child_panic, "Last panic at: %s\n", time_str);
vsb_cat(child_panic, vsm_head->panicstr);
vsb_finish(child_panic);
AZ(vsb_overflowed(child_panic));
}
static void
mgt_clear_panic(void)
{
vsb_delete(child_panic);
child_panic = NULL;
}
/*--------------------------------------------------------------------*/
static int
......@@ -478,6 +505,7 @@ mgt_sigchld(const struct vev *e, int what)
vsb_delete(vsb);
mgt_report_panic(r);
mgt_save_panic();
child_pid = -1;
......@@ -614,3 +642,33 @@ mcf_server_status(struct cli *cli, const char * const *av, void *priv)
(void)priv;
cli_out(cli, "Child in state %s", ch_state[child_state]);
}
void
mcf_panic_show(struct cli *cli, const char * const *av, void *priv)
{
(void)av;
(void)priv;
if (!child_panic) {
cli_result(cli, CLIS_CANT);
cli_out(cli, "Child has not panicked or panic has been cleared");
return;
}
cli_out(cli, "%s\n", vsb_data(child_panic));
}
void
mcf_panic_clear(struct cli *cli, const char * const *av, void *priv)
{
(void)av;
(void)priv;
if (!child_panic) {
cli_result(cli, CLIS_CANT);
cli_out(cli, "No panic to clear");
return;
}
mgt_clear_panic();
}
......@@ -127,6 +127,8 @@ static struct cli_proto cli_proto[] = {
{ CLI_VCL_SHOW, "", mcf_config_show, NULL },
{ CLI_PARAM_SHOW, "", mcf_param_show, NULL },
{ CLI_PARAM_SET, "", mcf_param_set, NULL },
{ CLI_PANIC_SHOW, "", mcf_panic_show, NULL },
{ CLI_PANIC_CLEAR, "", mcf_panic_clear, NULL },
{ NULL }
};
......
......@@ -32,6 +32,8 @@
/* mgt_child.c */
cli_func_t mcf_server_startstop;
cli_func_t mcf_server_status;
cli_func_t mcf_panic_show;
cli_func_t mcf_panic_clear;
/* mgt_param.c */
cli_func_t mcf_param_show;
......
......@@ -45,3 +45,7 @@ client c1 {
rxresp
expect resp.http.foo == "foo"
} -run
varnish v1 -cliok "panic.show"
varnish v1 -cliok "panic.clear"
varnish v1 -clierr 300 "panic.clear"
......@@ -230,6 +230,18 @@
"\tAuthenticate.", \
1, 1
#define CLI_PANIC_SHOW \
"panic.show", \
"panic.show", \
"\tReturn the last panic, if any.", \
0, 0
#define CLI_PANIC_CLEAR \
"panic.clear", \
"panic.clear", \
"\tClear the last panic, if any.", \
0, 0
#define CLI_HIDDEN(foo, min_arg, max_arg) \
foo, NULL, NULL, min_arg, max_arg,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment