r2971 - in trunk/varnish-cache: bin/varnishd include

phk at projects.linpro.no phk at projects.linpro.no
Sun Jul 20 12:36:28 CEST 2008


Author: phk
Date: 2008-07-20 12:36:28 +0200 (Sun, 20 Jul 2008)
New Revision: 2971

Modified:
   trunk/varnish-cache/bin/varnishd/cache.h
   trunk/varnish-cache/bin/varnishd/cache_main.c
   trunk/varnish-cache/bin/varnishd/cache_panic.c
   trunk/varnish-cache/bin/varnishd/common.h
   trunk/varnish-cache/bin/varnishd/mgt_child.c
   trunk/varnish-cache/bin/varnishd/shmlog.c
   trunk/varnish-cache/include/shmlog.h
Log:
Make room in the shared memory segment for a panic string
buffer.

Replace the default libvarnish assert handler with a child specific
function.

This function which fills the static panic string and copy the
result to the shared memory panicstring.

In the manager process, report the content of the panic string
when the child dies.


Modified: trunk/varnish-cache/bin/varnishd/cache.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache.h	2008-07-20 10:03:42 UTC (rev 2970)
+++ trunk/varnish-cache/bin/varnishd/cache.h	2008-07-20 10:36:28 UTC (rev 2971)
@@ -514,6 +514,9 @@
 void THR_SetSession(const struct sess *sp);
 const struct sess * THR_GetSession(void);
 
+/* cache_panic.c */
+void PAN_Init(void);
+
 /* cache_pipe.c */
 void PipeSession(struct sess *sp);
 
@@ -537,7 +540,6 @@
 void SES_Charge(struct sess *sp);
 
 /* cache_shmlog.c */
-
 void VSL_Init(void);
 #ifdef SHMLOGHEAD_MAGIC
 void VSL(enum shmlogtag tag, int id, const char *fmt, ...);

Modified: trunk/varnish-cache/bin/varnishd/cache_main.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_main.c	2008-07-20 10:03:42 UTC (rev 2970)
+++ trunk/varnish-cache/bin/varnishd/cache_main.c	2008-07-20 10:36:28 UTC (rev 2971)
@@ -94,6 +94,7 @@
 
 	THR_Name("cache-main");
 
+	PAN_Init();
 	CLI_Init();
 	Fetch_Init();
 

Modified: trunk/varnish-cache/bin/varnishd/cache_panic.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_panic.c	2008-07-20 10:03:42 UTC (rev 2970)
+++ trunk/varnish-cache/bin/varnishd/cache_panic.c	2008-07-20 10:36:28 UTC (rev 2971)
@@ -48,6 +48,8 @@
  * (gdb) printf "%s", panicstr
  */
 char panicstr[65536];
+static struct vsb vsps, *vsp;
+
 static char *pstr = panicstr;
 
 #define fp(...)							\
@@ -240,3 +242,41 @@
 }
 
 #endif
+
+static void
+pan_ic(const char *func, const char *file, int line, const char *cond, int err, int xxx)
+{
+	int l;
+	char *p;
+
+	if (xxx) {
+		vsb_printf(vsp,
+		    "Missing errorhandling code in %s(), %s line %d:\n"
+		    "  Condition(%s) not true.\n",
+		    func, file, line, cond);
+	} else {
+		vsb_printf(vsp,
+		    "Assert error in %s(), %s line %d:\n"
+		    "  Condition(%s) not true.\n",
+		    func, file, line, cond);
+	}
+	if (err)
+		vsb_printf(vsp,
+		    "  errno = %d (%s)\n", err, strerror(err));
+
+	VSL_Panic(&l, &p);
+	if (l < vsb_len(vsp))
+		l = vsb_len(vsp);
+	memcpy(p, panicstr, l);
+	abort();
+}
+
+
+void
+PAN_Init(void)
+{
+
+	lbv_assert = pan_ic;
+	vsp = &vsps;
+	AN(vsb_new(vsp, panicstr, sizeof panicstr, VSB_FIXEDLEN));
+}

Modified: trunk/varnish-cache/bin/varnishd/common.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/common.h	2008-07-20 10:03:42 UTC (rev 2970)
+++ trunk/varnish-cache/bin/varnishd/common.h	2008-07-20 10:36:28 UTC (rev 2971)
@@ -35,6 +35,8 @@
 /* cache_acceptor.c */
 void VCA_tweak_acceptor(struct cli *cli, const char *arg);
 
+/* shmlog.c */
+void VSL_Panic(int *len, char **ptr);
 
 /* shmlog.c */
 void VSL_MgtInit(const char *fn, unsigned size);

Modified: trunk/varnish-cache/bin/varnishd/mgt_child.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/mgt_child.c	2008-07-20 10:03:42 UTC (rev 2970)
+++ trunk/varnish-cache/bin/varnishd/mgt_child.c	2008-07-20 10:36:28 UTC (rev 2971)
@@ -375,6 +375,20 @@
 
 /*--------------------------------------------------------------------*/
 
+static void
+mgt_report_panic(pid_t r)
+{
+	int l;
+	char *p;
+
+	VSL_Panic(&l, &p);
+	if (*p == '\0')
+		return;
+	REPORT(LOG_ERR, "Child (%d) Panic message: %s", r, p);
+}
+
+/*--------------------------------------------------------------------*/
+
 static int
 mgt_sigchld(const struct vev *e, int what)
 {
@@ -411,6 +425,8 @@
 	REPORT(LOG_INFO, "%s", vsb_data(vsb));
 	vsb_delete(vsb);
 
+	mgt_report_panic(r);
+
 	child_pid = -1;
 
 	if (child_state == CH_RUNNING) {

Modified: trunk/varnish-cache/bin/varnishd/shmlog.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/shmlog.c	2008-07-20 10:03:42 UTC (rev 2970)
+++ trunk/varnish-cache/bin/varnishd/shmlog.c	2008-07-20 10:36:28 UTC (rev 2971)
@@ -265,6 +265,20 @@
 /*--------------------------------------------------------------------*/
 
 void
+VSL_Panic(int *len, char **ptr)
+{
+
+	AN(len);
+	AN(ptr);
+	assert(loghead->magic == SHMLOGHEAD_MAGIC);
+	assert(loghead->hdrsize == sizeof *loghead);
+	*len = sizeof(loghead->panicstr);
+	*ptr = loghead->panicstr;
+}
+
+/*--------------------------------------------------------------------*/
+
+void
 VSL_Init(void)
 {
 
@@ -274,6 +288,7 @@
 	logstart = (unsigned char *)loghead + loghead->start;
 	MTX_INIT(&vsl_mtx);
 	loghead->starttime = TIM_real();
+	loghead->panicstr[0] = '\0';
 	memset(VSL_stats, 0, sizeof *VSL_stats);
 }
 

Modified: trunk/varnish-cache/include/shmlog.h
===================================================================
--- trunk/varnish-cache/include/shmlog.h	2008-07-20 10:03:42 UTC (rev 2970)
+++ trunk/varnish-cache/include/shmlog.h	2008-07-20 10:36:28 UTC (rev 2971)
@@ -63,6 +63,9 @@
 	unsigned		ptr;
 
 	struct varnish_stats	stats;
+
+	/* Panic message buffer */
+	char			panicstr[64 * 1024];
 };
 
 /*




More information about the varnish-commit mailing list