Commit 63a34452 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

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.


git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@2971 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent bb974b0f
......@@ -514,6 +514,9 @@ void THR_Name(const char *name);
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_RefSrcAddr(struct sess *sp);
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, ...);
......
......@@ -94,6 +94,7 @@ child_main(void)
THR_Name("cache-main");
PAN_Init();
CLI_Init();
Fetch_Init();
......
......@@ -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 @@ panic(const char *file, int line, const char *func,
}
#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));
}
......@@ -35,6 +35,8 @@ struct sockaddr;
/* 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);
......
......@@ -375,6 +375,20 @@ mgt_stop_child(void)
/*--------------------------------------------------------------------*/
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 @@ mgt_sigchld(const struct vev *e, int what)
REPORT(LOG_INFO, "%s", vsb_data(vsb));
vsb_delete(vsb);
mgt_report_panic(r);
child_pid = -1;
if (child_state == CH_RUNNING) {
......
......@@ -264,6 +264,20 @@ WSL(struct worker *w, enum shmlogtag tag, int id, const char *fmt, ...)
/*--------------------------------------------------------------------*/
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 @@ VSL_Init(void)
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);
}
......
......@@ -63,6 +63,9 @@ struct shmloghead {
unsigned ptr;
struct varnish_stats stats;
/* Panic message buffer */
char panicstr[64 * 1024];
};
/*
......
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