0
0
Fork 0
mirror of https://github.com/netdata/netdata.git synced 2025-04-06 22:38:55 +00:00

disable UNW_LOCAL_ONLY on static builds ()

* disable UNW_LOCAL_ONLY on static builds

* disable stack traces with logs; get stack traces on deadly conditions only after saving status file

* signal handler safety only when UNW_LOCAL_ONLY is set

* removed warning
This commit is contained in:
Costa Tsaousis 2025-03-13 20:51:52 +00:00 committed by GitHub
parent c718bca80d
commit b942b581a5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 32 additions and 9 deletions

View file

@ -13,6 +13,7 @@
#cmakedefine OS_LINUX
#cmakedefine OS_MACOS
#cmakedefine OS_WINDOWS
#cmakedefine STATIC_BUILD
// required compilation options

View file

@ -1115,6 +1115,22 @@ void daemon_status_file_check_crash(void) {
}
}
static void daemon_status_file_save_again_if_we_can_get_stack_trace(void) {
if(!session_status.fatal.stack_trace[0]) {
buffer_flush(static_save_buffer);
capture_stack_trace(static_save_buffer);
if(buffer_strlen(static_save_buffer) > 0) {
strncpyz(
session_status.fatal.stack_trace,
buffer_tostring(static_save_buffer),
sizeof(session_status.fatal.stack_trace) - 1);
daemon_status_file_save(static_save_buffer, &session_status, false);
}
}
}
// --------------------------------------------------------------------------------------------------------------------
// ng_log() hook for receiving fatal message information
@ -1156,6 +1172,8 @@ void daemon_status_file_register_fatal(const char *filename, const char *functio
freez((void *)message);
freez((void *)errno_str);
freez((void *)stack_trace);
daemon_status_file_save_again_if_we_can_get_stack_trace();
}
// --------------------------------------------------------------------------------------------------------------------
@ -1181,6 +1199,7 @@ static void daemon_status_file_out_of_memory(void) {
dsf_release(session_status);
daemon_status_file_save(static_save_buffer, &session_status, false);
daemon_status_file_save_again_if_we_can_get_stack_trace();
}
void daemon_status_file_deadly_signal_received(EXIT_REASON reason) {
@ -1202,14 +1221,8 @@ void daemon_status_file_deadly_signal_received(EXIT_REASON reason) {
// save what we know already
daemon_status_file_save(static_save_buffer, &session_status, false);
bool can_safely_capture_stack_trace = reason != EXIT_REASON_SIGABRT || capture_stack_trace_is_async_signal_safe();
if(can_safely_capture_stack_trace && !session_status.fatal.stack_trace[0]) {
buffer_flush(static_save_buffer);
capture_stack_trace(static_save_buffer);
strncpyz(session_status.fatal.stack_trace, buffer_tostring(static_save_buffer), sizeof(session_status.fatal.stack_trace) - 1);
daemon_status_file_save(static_save_buffer, &session_status, false);
}
if(reason != EXIT_REASON_SIGABRT || capture_stack_trace_is_async_signal_safe())
daemon_status_file_save_again_if_we_can_get_stack_trace();
}
bool daemon_status_file_has_last_crashed(void) {

View file

@ -7,7 +7,9 @@ bool nd_log_forked = false;
#define NO_STACK_TRACE_PREFIX "stack trace not available: "
#if defined(HAVE_LIBUNWIND)
#if !defined(STATIC_BUILD)
#define UNW_LOCAL_ONLY
#endif
#include <libunwind.h>
void capture_stack_trace_init(void) {
@ -19,7 +21,11 @@ void capture_stack_trace_flush(void) {
}
bool capture_stack_trace_is_async_signal_safe(void) {
#if defined(STATIC_BUILD)
return false;
#else
return true;
#endif
}
void capture_stack_trace(BUFFER *wb) {

View file

@ -268,8 +268,11 @@ static void nd_logger(const char *file, const char *function, const unsigned lon
// set the common fields that are automatically set by the logging subsystem
if(likely(!thread_log_fields[NDF_STACK_TRACE].entry.set) && priority <= NDLP_WARNING)
#if 0
// getting stack traces is crashing on some architectures, so we get them only for daemon status file
if(likely(!thread_log_fields[NDF_STACK_TRACE].entry.set) && priority <= NDLP_ALERT) // only on fatal errors
thread_log_fields[NDF_STACK_TRACE].entry = ND_LOG_FIELD_CB(NDF_STACK_TRACE, stack_trace_formatter, NULL);
#endif
if(likely(!thread_log_fields[NDF_INVOCATION_ID].entry.set))
thread_log_fields[NDF_INVOCATION_ID].entry = ND_LOG_FIELD_UUID(NDF_INVOCATION_ID, &nd_log.invocation_id);