diff options
| author | David Lamparter <equinox@diac24.net> | 2021-03-16 11:03:44 +0100 | 
|---|---|---|
| committer | David Lamparter <equinox@opensourcerouting.org> | 2021-05-02 16:27:17 +0200 | 
| commit | 64dd77361f7ab97365d264408afb538097c0339c (patch) | |
| tree | fb9350dd6f43fae80b8d3e67cbb285901f42e125 /lib/zlog.c | |
| parent | 642ac49da40a196c4e4ad74128de2056237d3cb4 (diff) | |
lib: rework how we "override" assert()
The previous method, using zassert.h and hoping nothing includes
assert.h (which, on glibc at least, just does "#undef assert" and puts
its own definition in...) was fragile - and actually broke undetected.
Just provide our own assert.h and control overriding by putting it in a
separate directory to add to the include path (or not.)
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
Diffstat (limited to 'lib/zlog.c')
| -rw-r--r-- | lib/zlog.c | 30 | 
1 files changed, 30 insertions, 0 deletions
diff --git a/lib/zlog.c b/lib/zlog.c index 24800c6e64..d2851c6028 100644 --- a/lib/zlog.c +++ b/lib/zlog.c @@ -521,6 +521,36 @@ void zlog_sigsafe(const char *text, size_t len)  	}  } +void _zlog_assert_failed(const struct xref_assert *xref, const char *extra, ...) +{ +	va_list ap; +	static bool assert_in_assert; /* "global-ish" variable, init to 0 */ + +	if (assert_in_assert) +		abort(); +	assert_in_assert = true; + +	if (extra) { +		struct va_format vaf; + +		va_start(ap, extra); +		vaf.fmt = extra; +		vaf.va = ≈ + +		zlog(LOG_CRIT, +		     "%s:%d: %s(): assertion (%s) failed, extra info: %pVA", +		     xref->xref.file, xref->xref.line, xref->xref.func, +		     xref->expr, &vaf); + +		va_end(ap); +	} else +		zlog(LOG_CRIT, "%s:%d: %s(): assertion (%s) failed", +		     xref->xref.file, xref->xref.line, xref->xref.func, +		     xref->expr); + +	/* abort() prints backtrace & memstats in SIGABRT handler */ +	abort(); +}  int zlog_msg_prio(struct zlog_msg *msg)  {  | 
