From fe0a330786720e01908ce1a5758979195178ee0d Mon Sep 17 00:00:00 2001 From: phk Date: Fri, 15 Feb 2008 12:30:47 +0000 Subject: [PATCH] Use the abort2(2) function to record our panic string, if we have it. Protect macros with do {....} while(0) git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@2478 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/bin/varnishd/cache_panic.c | 40 +++++++++++++++++------- varnish-cache/configure.ac | 1 + varnish-cache/include/cli_common.h | 1 + 3 files changed, 31 insertions(+), 11 deletions(-) diff --git a/varnish-cache/bin/varnishd/cache_panic.c b/varnish-cache/bin/varnishd/cache_panic.c index f2c6d97c..22dc6c8e 100644 --- a/varnish-cache/bin/varnishd/cache_panic.c +++ b/varnish-cache/bin/varnishd/cache_panic.c @@ -34,6 +34,7 @@ #include #include #include +#include #include "cache.h" @@ -48,14 +49,19 @@ char panicstr[65536]; static char *pstr = panicstr; -#define fp(...) \ - pstr += snprintf(pstr, \ - (panicstr + sizeof panicstr) - pstr, \ - __VA_ARGS__) -#define vfp(fmt, ap) \ - pstr += vsnprintf(pstr, \ - (panicstr + sizeof panicstr) - pstr, \ - (fmt), (ap)) +#define fp(...) \ + do { \ + pstr += snprintf(pstr, \ + (panicstr + sizeof panicstr) - pstr, \ + __VA_ARGS__); \ + } while (0) + +#define vfp(fmt, ap) \ + do { \ + pstr += vsnprintf(pstr, \ + (panicstr + sizeof panicstr) - pstr, \ + (fmt), (ap)); \ + } while (0) /* step names */ static const char *steps[] = { @@ -195,11 +201,23 @@ panic(const char *file, int line, const char *func, if (VALID_OBJ(sp, SESS_MAGIC)) dump_sess(sp); - fputs(panicstr, stderr); + (void)fputs(panicstr, stderr); /* I wish there was a way to flush the log buffers... */ - signal(SIGABRT, SIG_DFL); - raise(SIGABRT); + (void)signal(SIGABRT, SIG_DFL); +#ifdef HAVE_ABORT2 + { + void *arg[1]; + char *p; + + for (p = panicstr; *p; p++) + if (*p == '\n') + *p = ' '; + arg[0] = panicstr; + abort2(panicstr, 1, arg); + } +#endif + (void)raise(SIGABRT); } #endif diff --git a/varnish-cache/configure.ac b/varnish-cache/configure.ac index ec36bda7..f3f0457c 100644 --- a/varnish-cache/configure.ac +++ b/varnish-cache/configure.ac @@ -100,6 +100,7 @@ AC_CHECK_FUNCS([socket]) AC_CHECK_FUNCS([strptime]) AC_CHECK_FUNCS([fmtcheck]) AC_CHECK_FUNCS([getdtablesize]) +AC_CHECK_FUNCS([abort2]) save_LIBS="${LIBS}" LIBS="${PTHREAD_LIBS}" diff --git a/varnish-cache/include/cli_common.h b/varnish-cache/include/cli_common.h index 04fff6f8..53bec5e9 100644 --- a/varnish-cache/include/cli_common.h +++ b/varnish-cache/include/cli_common.h @@ -30,6 +30,7 @@ */ struct cli { + /* XXX: should be MINI_OBJ */ struct vsb *sb; enum cli_status_e result; }; -- 2.39.5