Skip to content
Permalink
Browse files

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

This avoids infinite recursion if the printing causes another signal.
  • Loading branch information
SimonSapin committed Nov 27, 2019
1 parent 413f499 commit 99804eb5a6a6c2f4b1384f735cc43f2cc8b61b4f
Showing with 9 additions and 6 deletions.
  1. +9 −6 ports/glutin/main2.rs
@@ -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);
}

0 comments on commit 99804eb

Please sign in to comment.
You can’t perform that action at this time.