[PATCH] Add lastpanic CLI command, dumping the last panic string

Tollef Fog Heen tfheen at varnish-software.com
Thu Mar 10 13:37:56 CET 2011


---
 bin/varnishd/cache_cli.c |    1 +
 bin/varnishd/mgt_child.c |   31 +++++++++++++++++++++++++++++++
 bin/varnishd/mgt_cli.c   |    1 +
 bin/varnishd/mgt_cli.h   |    1 +
 include/cli.h            |    6 ++++++
 5 files changed, 40 insertions(+), 0 deletions(-)

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..02d2ff5 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,24 @@ 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_printf(child_panic, "%s", vsm_head->panicstr);
+	vsb_finish(child_panic);
+	AZ(vsb_overflowed(child_panic));
+}
+
 /*--------------------------------------------------------------------*/
 
 static int
@@ -478,6 +498,7 @@ mgt_sigchld(const struct vev *e, int what)
 	vsb_delete(vsb);
 
 	mgt_report_panic(r);
+	mgt_save_panic();
 
 	child_pid = -1;
 
@@ -614,3 +635,13 @@ 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_lastpanic(struct cli *cli, const char * const *av, void *priv)
+{
+	(void)av;
+	(void)priv;
+
+	if (child_panic)
+		cli_out(cli, "%s\n", vsb_data(child_panic));
+}
diff --git a/bin/varnishd/mgt_cli.c b/bin/varnishd/mgt_cli.c
index 7f719a0..48b7295 100644
--- a/bin/varnishd/mgt_cli.c
+++ b/bin/varnishd/mgt_cli.c
@@ -127,6 +127,7 @@ 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_LASTPANIC,	"", mcf_lastpanic, NULL },
 	{ NULL }
 };
 
diff --git a/bin/varnishd/mgt_cli.h b/bin/varnishd/mgt_cli.h
index c4bfd5a..e3f61cc 100644
--- a/bin/varnishd/mgt_cli.h
+++ b/bin/varnishd/mgt_cli.h
@@ -32,6 +32,7 @@
 /* mgt_child.c */
 cli_func_t mcf_server_startstop;
 cli_func_t mcf_server_status;
+cli_func_t mcf_lastpanic;
 
 /* mgt_param.c */
 cli_func_t mcf_param_show;
diff --git a/include/cli.h b/include/cli.h
index e16ff60..5dc5e80 100644
--- a/include/cli.h
+++ b/include/cli.h
@@ -230,6 +230,12 @@
 	"\tAuthenticate.",						\
 	1, 1
 
+#define CLI_LASTPANIC							\
+	"lastpanic",							\
+	"lastpanic",							\
+	"\tReturn the last panic, if any.",				\
+	0, 0
+
 #define CLI_HIDDEN(foo, min_arg, max_arg)				\
 	foo, NULL, NULL, min_arg, max_arg,
 
-- 
1.7.2.3




More information about the varnish-dev mailing list