116#ifndef MHD_PANIC_TRIPWIRE_H
117#define MHD_PANIC_TRIPWIRE_H 1
132#define MHD_PANIC_TRIPWIRE_MARKER "MHD-PANIC-TRIPWIRE"
138#define MHD_PANIC_TRIPWIRE_EXIT_STATUS 99
143#if ! defined(MHD_PANIC_TRIPWIRE_BACKTRACE_)
144# if defined(__has_include )
145# if __has_include (<execinfo.h>)
146# define MHD_PANIC_TRIPWIRE_BACKTRACE_ 1
148# elif defined(HAVE_EXECINFO_H) || defined(__GLIBC__)
149# define MHD_PANIC_TRIPWIRE_BACKTRACE_ 1
152#ifdef MHD_PANIC_TRIPWIRE_BACKTRACE_
160#if defined(__GNUC__) && defined(__ELF__) && ! defined(_WIN32)
161# define MHD_PANIC_TRIPWIRE_WEAK_ __attribute__ ((weak))
164#ifdef MHD_PANIC_TRIPWIRE_WEAK_
170extern MHD_PANIC_TRIPWIRE_WEAK_
void
179#if defined(__GNUC__) || defined(__clang__)
180# define MHD_PANIC_TRIPWIRE_UNUSED_ __attribute__ ((unused))
181# define MHD_PANIC_TRIPWIRE_NORETURN_ __attribute__ ((noreturn))
183# define MHD_PANIC_TRIPWIRE_UNUSED_
184# define MHD_PANIC_TRIPWIRE_NORETURN_
212#define MHD_PANIC_TRIPWIRE_WRS_(str) \
213 mhd_panic_tripwire_wr_ (str, sizeof(str) - 1)
232 int res = _write (2, buf + off, (
unsigned int) (len - off));
234 ssize_t res = write (STDERR_FILENO, buf + off, len - off);
262 const unsigned char chr = (
unsigned char) *str++;
264 chunk[used++] = (0x20 > chr) ?
' ' : (char) chr;
265 if (
sizeof(chunk) == used)
285 size_t pos =
sizeof(buf);
289 buf[--pos] = (char) (
'0' + (val % 10));
303#ifdef MHD_PANIC_TRIPWIRE_BACKTRACE_
307 num = backtrace (frames, (
int) (
sizeof(frames) /
sizeof(frames[0])));
314 backtrace_symbols_fd (frames, num, 2);
350 ": terminating with exit status ");
356 ": re-raising SIGABRT for a core dump\n");
360 signal (SIGABRT, SIG_DFL);
403 "abort() reached; see the line above for the "
404 "failed assertion, if any");
419 return (0 == strcmp (val,
"0")) ||
420 (0 == strcmp (val,
"off")) ||
421 (0 == strcmp (val,
"no")) ||
422 (0 == strcmp (val,
"disable"));
434 const char *mode = getenv (
"MHD_TEST_PANIC_TRIPWIRE");
438 if ((
NULL != mode) && (0 == strcmp (mode,
"abort")))
440 else if ((
NULL != mode) && (0 == strncmp (mode,
"exit:", 5)))
442 const long status = strtol (mode + 5,
NULL, 10);
444 if ((0 <= status) && (255 >= status))
447#ifdef MHD_PANIC_TRIPWIRE_WEAK_
461#if defined(__GNUC__) || defined(__clang__)
468__attribute__ ((constructor))
static void
469mhd_panic_tripwire_ctor_ (
void)
_MHD_EXTERN void MHD_set_panic_func(MHD_PanicCallback cb, void *cls)
static int mhd_panic_tripwire_is_off_(const char *val)
static void mhd_panic_tripwire_wr_clean_(const char *str)
static volatile sig_atomic_t mhd_panic_tripwire_status_
#define MHD_PANIC_TRIPWIRE_UNUSED_
#define MHD_PANIC_TRIPWIRE_MARKER
static MHD_PANIC_TRIPWIRE_UNUSED_ void mhd_panic_tripwire_install(void)
static void mhd_panic_tripwire_wr_(const char *buf, size_t len)
static void mhd_panic_tripwire_abrt_cb_(int sig)
static volatile sig_atomic_t mhd_panic_tripwire_reraise_
static void mhd_panic_tripwire_backtrace_(void)
static MHD_PANIC_TRIPWIRE_NORETURN_ void mhd_panic_tripwire_report_(const char *kind, const char *file, unsigned int line, const char *reason)
#define MHD_PANIC_TRIPWIRE_WRS_(str)
#define MHD_PANIC_TRIPWIRE_NORETURN_
#define MHD_PANIC_TRIPWIRE_EXIT_STATUS
static void mhd_panic_tripwire_panic_cb_(void *cls, const char *file, unsigned int line, const char *reason)
static void mhd_panic_tripwire_wr_num_(unsigned long val)
static volatile sig_atomic_t mhd_panic_tripwire_busy_