From 3063b41b07b37a04bfafce7780a5c8e1b1ed23d3 Mon Sep 17 00:00:00 2001 From: phk Date: Sun, 20 Jul 2008 10:36:28 +0000 Subject: [PATCH] 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: svn+ssh://projects.linpro.no/svn/varnish/trunk@2971 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/bin/varnishd/cache.h | 4 ++- varnish-cache/bin/varnishd/cache_main.c | 1 + varnish-cache/bin/varnishd/cache_panic.c | 40 ++++++++++++++++++++++++ varnish-cache/bin/varnishd/common.h | 2 ++ varnish-cache/bin/varnishd/mgt_child.c | 16 ++++++++++ varnish-cache/bin/varnishd/shmlog.c | 15 +++++++++ varnish-cache/include/shmlog.h | 3 ++ 7 files changed, 80 insertions(+), 1 deletion(-) diff --git a/varnish-cache/bin/varnishd/cache.h b/varnish-cache/bin/varnishd/cache.h index 7119095a..b72f36be 100644 --- a/varnish-cache/bin/varnishd/cache.h +++ b/varnish-cache/bin/varnishd/cache.h @@ -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, ...); diff --git a/varnish-cache/bin/varnishd/cache_main.c b/varnish-cache/bin/varnishd/cache_main.c index 19446bd8..64405405 100644 --- a/varnish-cache/bin/varnishd/cache_main.c +++ b/varnish-cache/bin/varnishd/cache_main.c @@ -94,6 +94,7 @@ child_main(void) THR_Name("cache-main"); + PAN_Init(); CLI_Init(); Fetch_Init(); diff --git a/varnish-cache/bin/varnishd/cache_panic.c b/varnish-cache/bin/varnishd/cache_panic.c index 1232397a..ee630527 100644 --- a/varnish-cache/bin/varnishd/cache_panic.c +++ b/varnish-cache/bin/varnishd/cache_panic.c @@ -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)); +} diff --git a/varnish-cache/bin/varnishd/common.h b/varnish-cache/bin/varnishd/common.h index d8f1347a..849660e6 100644 --- a/varnish-cache/bin/varnishd/common.h +++ b/varnish-cache/bin/varnishd/common.h @@ -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); diff --git a/varnish-cache/bin/varnishd/mgt_child.c b/varnish-cache/bin/varnishd/mgt_child.c index 6fd8d0b0..fede7fda 100644 --- a/varnish-cache/bin/varnishd/mgt_child.c +++ b/varnish-cache/bin/varnishd/mgt_child.c @@ -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) { diff --git a/varnish-cache/bin/varnishd/shmlog.c b/varnish-cache/bin/varnishd/shmlog.c index 6ff647cb..c2d6cb66 100644 --- a/varnish-cache/bin/varnishd/shmlog.c +++ b/varnish-cache/bin/varnishd/shmlog.c @@ -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); } diff --git a/varnish-cache/include/shmlog.h b/varnish-cache/include/shmlog.h index 4bceb4c4..f06b3524 100644 --- a/varnish-cache/include/shmlog.h +++ b/varnish-cache/include/shmlog.h @@ -63,6 +63,9 @@ struct shmloghead { unsigned ptr; struct varnish_stats stats; + + /* Panic message buffer */ + char panicstr[64 * 1024]; }; /* -- 2.39.5