Only print a backtrace the first time the signal handler is called.

This avoids infinite recursion if the printing causes another signal.
This commit is contained in:
Simon Sapin 2019-11-27 20:35:41 +01:00
parent 413f499da8
commit 99804eb5a6

View file

@ -31,7 +31,6 @@ use servo::servo_config::pref;
use std::env;
use std::panic;
use std::process;
use std::sync::atomic;
use std::thread;
pub mod platform {
@ -55,12 +54,16 @@ fn install_crash_handler() {
use std::thread;
extern "C" fn handler(sig: i32) {
print!("Stack trace");
if let Some(name) = thread::current().name() {
print!(" for thread \"{}\"", name);
use std::sync::atomic;
static BEEN_HERE_BEFORE: atomic::AtomicBool = atomic::AtomicBool::new(false);
if !BEEN_HERE_BEFORE.swap(true, atomic::Ordering::SeqCst) {
print!("Stack trace");
if let Some(name) = thread::current().name() {
print!(" for thread \"{}\"", name);
}
println!();
backtrace::print();
}
println!();
backtrace::print();
unsafe {
_exit(sig);
}