From 0d2cd10fba86011a01a1c52c0db2e98660efa1de Mon Sep 17 00:00:00 2001 From: dequis Date: Mon, 26 Mar 2018 13:26:56 -0300 Subject: Write backtrace to /var/lib/bitlbee/crash.log on SIGSEGV Async-signal-safe code is very restricted (nothing that may call malloc indirectly), so this code tries its best to show meaningful stuff, but the output is still fairly raw. The contents of the log file are: - BITLBEE_VERSION, BITLBEE_CONFIGURE_ARGS - Backtrace as generated by backtrace()/backtrace_symbols_fd() - A small help text explaining how to get more useful symbol names - Memory maps (/proc/self/maps), which also mentions loaded plugins The backtrace() function is a GNU extension, /proc/ is a linux thing. Non-glibc platforms (such as musl) won't show anything, non-linux platforms will skip the memory maps when /proc/self/maps fails to open. I'd like to include timestamps, but I can't find a safe way to format them. Even turning raw unix timestamps to strings is hard. Fun stuff. I used the config directory because it's the only place we can be sure we can write to. The filename is hardcoded for the same reason there are no timestamps. --- configure | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'configure') diff --git a/configure b/configure index 093fbf3d..b578164f 100755 --- a/configure +++ b/configure @@ -484,6 +484,16 @@ int main() } ' +BACKTRACE_TESTCODE=' +#include + +int main() +{ + void *trace[16]; + return backtrace(trace, 16); +} +' + detect_resolv_dynamic() { case "$arch" in @@ -581,6 +591,19 @@ detect_nameser_has_ns_types() return $ret } +detect_backtrace() +{ + TMPFILE=$(mktemp /tmp/bitlbee-configure.XXXXXX) + ret=1 + echo "$BACKTRACE_TESTCODE" | $CC -o $TMPFILE -x c - >/dev/null 2>/dev/null + if [ "$?" = "0" ]; then + ret=0 + fi + + rm -f $TMPFILE + return $ret +} + if [ "$ssl" = "auto" ]; then detect_gnutls if [ "$ret" = "0" ]; then @@ -646,6 +669,10 @@ else echo 'Insufficient resolv routines. Jabber server must be set explicitly' fi +if detect_backtrace; then + echo '#define HAVE_BACKTRACE' >> config.h + echo '#define CRASHFILE "'$config'crash.log"' >> config.h +fi STORAGES="xml" -- cgit v1.2.3