aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt4
-rw-r--r--config.h.in1
-rw-r--r--src/libserver/worker_util.c21
3 files changed, 21 insertions, 5 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index efda209ca..58839fbf9 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -210,6 +210,8 @@ IF (ENABLE_LIBUNWIND MATCHES "ON")
ProcessPackage(LIBUNWIND LIBRARY unwind INCLUDE libunwind.h INCLUDE_SUFFIXES include/libunwind
ROOT ${LIBUNWIND_ROOT_DIR} MODULES libunwind)
SET(WITH_LIBUNWIND "1")
+ELSE ()
+ CHECK_SYMBOL_EXISTS(backtrace "execinfo.h" HAVE_BACKTRACE)
ENDIF ()
ProcessPackage(GLIB2 LIBRARY glib-2.0 INCLUDE glib.h
@@ -777,7 +779,7 @@ IF (NOT DEBIAN_BUILD)
ADD_CUSTOM_TARGET(check DEPENDS rspamd-test-cxx rspamd-test)
ADD_CUSTOM_TARGET(run-test DEPENDS check
COMMAND test/rspamd-test-cxx
- COMMAND sh -c 'LUA_PATH="${CMAKE_SOURCE_DIR}/lualib/?.lua\;${CMAKE_SOURCE_DIR}/lualib/?/?.lua\;${CMAKE_SOURCE_DIR}/lualib/?/init.lua\;${CMAKE_SOURCE_DIR}/contrib/lua-?/?.lua"
+ COMMAND sh -c 'LUA_PATH= "${CMAKE_SOURCE_DIR}/lualib/?.lua\;${CMAKE_SOURCE_DIR}/lualib/?/?.lua\;${CMAKE_SOURCE_DIR}/lualib/?/init.lua\;${CMAKE_SOURCE_DIR}/contrib/lua-?/?.lua"
test/rspamd-test -p /rspamd/lua')
ENDIF (NOT DEBIAN_BUILD)
diff --git a/config.h.in b/config.h.in
index 412dd53e4..44dc3cdf3 100644
--- a/config.h.in
+++ b/config.h.in
@@ -117,6 +117,7 @@
#cmakedefine WITH_LUA_TRACE 1
#cmakedefine WITH_LUA_REPL 1
#cmakedefine WITH_FASTTEXT 1
+#cmakedefine HAVE_BACKTRACE 1
#cmakedefine DISABLE_PTHREAD_MUTEX 1
diff --git a/src/libserver/worker_util.c b/src/libserver/worker_util.c
index d2a900e01..7f41b2cd3 100644
--- a/src/libserver/worker_util.c
+++ b/src/libserver/worker_util.c
@@ -1,11 +1,11 @@
-/*-
- * Copyright 2016 Vsevolod Stakhov
+/*
+ * Copyright 2023 Vsevolod Stakhov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -1658,6 +1658,19 @@ rspamd_print_crash(ucontext_t *uap)
msg_err("unw_step_ptr: %d", ret);
}
}
+#elif defined(HAVE_BACKTRACE)
+#include <execinfo.h>
+static void
+rspamd_print_crash(ucontext_t *_uap)
+{
+ void *callstack[128];
+ int i, frames = backtrace(callstack, 128);
+ char **strs = backtrace_symbols(callstack, frames);
+ for (i = 0; i < frames; ++i) {
+ msg_err("%d: %s", i, strs[i]);
+ }
+ free(strs);
+}
#endif
static struct rspamd_main *saved_main = NULL;
@@ -1684,7 +1697,7 @@ rspamd_crash_sig_handler(int sig, siginfo_t *info, void *ctx)
"pid: %P, trace: ",
sig, strsignal(sig), pid);
(void) uap;
-#ifdef WITH_LIBUNWIND
+#if defined(WITH_LIBUNWIND) || defined(HAVE_BACKTRACE)
rspamd_print_crash(uap);
#endif
msg_err("please see Rspamd FAQ to learn how to dump core files and how to "