diff --git a/Cargo.lock b/Cargo.lock index 6bb527bf96..1c793052c0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2974,6 +2974,7 @@ dependencies = [ "criterion", "cxx", "cxx-build", + "errno", "goblin", "http", "libc", diff --git a/libdd-crashtracker/Cargo.toml b/libdd-crashtracker/Cargo.toml index b4e34250d0..ebfa26a737 100644 --- a/libdd-crashtracker/Cargo.toml +++ b/libdd-crashtracker/Cargo.toml @@ -48,6 +48,7 @@ libdd-libunwind-sys = { version = "0.1.0", path = "../libdd-libunwind-sys" } anyhow = "1.0" chrono = {version = "0.4", default-features = false, features = ["std", "clock", "serde"]} cxx = { version = "1.0", optional = true } +errno = "0.3" libdd-common = { version = "3.0.0", path = "../libdd-common" } libdd-telemetry = { version = "3.0.0", path = "../libdd-telemetry" } http = "1.1" diff --git a/libdd-crashtracker/src/collector/crash_handler.rs b/libdd-crashtracker/src/collector/crash_handler.rs index 3a51f0d9ba..ece91c755c 100644 --- a/libdd-crashtracker/src/collector/crash_handler.rs +++ b/libdd-crashtracker/src/collector/crash_handler.rs @@ -9,6 +9,7 @@ use super::signal_handler_manager::chain_signal_handler; use crate::crash_info::Metadata; use crate::shared::configuration::CrashtrackerConfiguration; use crate::StackTrace; +use errno::{errno, set_errno}; use libc::{c_void, siginfo_t, ucontext_t}; use libdd_common::timeout::TimeoutManager; use std::os::fd::OwnedFd; @@ -193,10 +194,17 @@ pub(crate) extern "C" fn handle_posix_sigaction( sig_info: *mut siginfo_t, ucontext: *mut c_void, ) { + // Save errno + let errno = errno(); + // Handle the signal. Note this has a guard to ensure that we only generate // one crash report per process. let _ = handle_posix_signal_impl(sig_info, ucontext as *mut ucontext_t); + + // Restore errno + set_errno(errno); // SAFETY: No preconditions. + unsafe { chain_signal_handler(signum, sig_info, ucontext) }; }