]> err.no Git - varnish/commitdiff
Make room in the shared memory segment for a panic string
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Sun, 20 Jul 2008 10:36:28 +0000 (10:36 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Sun, 20 Jul 2008 10:36:28 +0000 (10:36 +0000)
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
varnish-cache/bin/varnishd/cache_main.c
varnish-cache/bin/varnishd/cache_panic.c
varnish-cache/bin/varnishd/common.h
varnish-cache/bin/varnishd/mgt_child.c
varnish-cache/bin/varnishd/shmlog.c
varnish-cache/include/shmlog.h

index 7119095a41b91d7b8536081ce09b0774b4396b77..b72f36be278168367ab49510582852f612e275e8 100644 (file)
@@ -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, ...);
index 19446bd8ce5de16d99c13eefc775f0d6c8c7e8d3..64405405d6046e1c026fd6c9ccfcbe9603508e88 100644 (file)
@@ -94,6 +94,7 @@ child_main(void)
 
        THR_Name("cache-main");
 
+       PAN_Init();
        CLI_Init();
        Fetch_Init();
 
index 1232397ac8d1ee8396a417445e03c92ae68a2e5e..ee6305276f797dad23686b99eaa085d2d93b4b99 100644 (file)
@@ -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));
+}
index d8f1347ac21871e33418277df83a44e92907a101..849660e6c9163ee7cb28059b8f597e0afbe857b6 100644 (file)
@@ -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);
index 6fd8d0b0fb29a81586909f7d56e255104e995a92..fede7fda552ba18abf5a57f8dd17a8054fccefab 100644 (file)
@@ -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) {
index 6ff647cb2ba5ca7754a004191fd98ee12b3335ac..c2d6cb6606f8f87f304159f1e01a65d6419bcc7c 100644 (file)
@@ -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);
 }
 
index 4bceb4c4653a59ae4f776ef903d1cd3ffcaf545a..f06b3524214a3cf74a1666b23d49a0b5d5191a29 100644 (file)
@@ -63,6 +63,9 @@ struct shmloghead {
        unsigned                ptr;
 
        struct varnish_stats    stats;
+
+       /* Panic message buffer */
+       char                    panicstr[64 * 1024];
 };
 
 /*