[master] 28dafef Add panic.show and panic.clear CLI commands

Tollef Fog Heen tfheen at varnish-cache.org
Mon Mar 14 13:31:03 CET 2011


commit 28dafefee8dd72f52fad515e24add2f44905d1a9
Author: Tollef Fog Heen <tfheen at varnish-software.com>
Date:   Thu Mar 10 13:34:58 2011 +0100

    Add panic.show and panic.clear CLI commands
    
    panic.show shows the last panic from the child
    panic.clear removes it.

diff --git a/bin/varnishd/cache_cli.c b/bin/varnishd/cache_cli.c
index dae6af5..056a63c 100644
--- a/bin/varnishd/cache_cli.c
+++ b/bin/varnishd/cache_cli.c
@@ -1,6 +1,7 @@
 /*-
  * 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 at phk.freebsd.dk>
diff --git a/bin/varnishd/mgt_child.c b/bin/varnishd/mgt_child.c
index d8cbc59..a670a36 100644
--- a/bin/varnishd/mgt_child.c
+++ b/bin/varnishd/mgt_child.c
@@ -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();
+}
diff --git a/bin/varnishd/mgt_cli.c b/bin/varnishd/mgt_cli.c
index 7f719a0..0b364fd 100644
--- a/bin/varnishd/mgt_cli.c
+++ b/bin/varnishd/mgt_cli.c
@@ -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 }
 };
 
diff --git a/bin/varnishd/mgt_cli.h b/bin/varnishd/mgt_cli.h
index c4bfd5a..f7a1797 100644
--- a/bin/varnishd/mgt_cli.h
+++ b/bin/varnishd/mgt_cli.h
@@ -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;
diff --git a/bin/varnishtest/tests/v00010.vtc b/bin/varnishtest/tests/v00010.vtc
index 4ef81f2..259894f 100644
--- a/bin/varnishtest/tests/v00010.vtc
+++ b/bin/varnishtest/tests/v00010.vtc
@@ -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"
diff --git a/include/cli.h b/include/cli.h
index e16ff60..3734b0b 100644
--- a/include/cli.h
+++ b/include/cli.h
@@ -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,
 



More information about the varnish-commit mailing list