mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
Try to avoid panicking during I/O in the signal and panic handlers.
This commit is contained in:
parent
4edd1590f4
commit
8fdec5bb50
2 changed files with 16 additions and 9 deletions
|
@ -13,8 +13,8 @@ use std::fmt::{self, Write};
|
|||
use backtrace::{BytesOrWideString, PrintFmt};
|
||||
|
||||
#[inline(never)]
|
||||
pub(crate) fn print() {
|
||||
println!("{:?}", Print {
|
||||
pub(crate) fn print(w: &mut dyn std::io::Write) -> Result<(), std::io::Error> {
|
||||
write!(w, "{:?}", Print {
|
||||
print_fn_address: print as usize,
|
||||
})
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ use servo::config::opts::{self, ArgumentParsingResult};
|
|||
use servo::config::servo_version;
|
||||
use servo::servo_config::pref;
|
||||
use std::env;
|
||||
use std::io::Write;
|
||||
use std::panic;
|
||||
use std::process;
|
||||
use std::thread;
|
||||
|
@ -57,12 +58,14 @@ fn install_crash_handler() {
|
|||
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");
|
||||
let stdout = std::io::stdout();
|
||||
let mut stdout = stdout.lock();
|
||||
let _ = write!(&mut stdout, "Stack trace");
|
||||
if let Some(name) = thread::current().name() {
|
||||
print!(" for thread \"{}\"", name);
|
||||
let _ = write!(&mut stdout, " for thread \"{}\"", name);
|
||||
}
|
||||
println!();
|
||||
backtrace::print();
|
||||
let _ = write!(&mut stdout, "\n");
|
||||
let _ = backtrace::print(&mut stdout);
|
||||
}
|
||||
unsafe {
|
||||
_exit(sig);
|
||||
|
@ -131,8 +134,11 @@ pub fn main() {
|
|||
};
|
||||
let current_thread = thread::current();
|
||||
let name = current_thread.name().unwrap_or("<unnamed>");
|
||||
let stdout = std::io::stdout();
|
||||
let mut stdout = stdout.lock();
|
||||
if let Some(location) = info.location() {
|
||||
println!(
|
||||
let _ = writeln!(
|
||||
&mut stdout,
|
||||
"{} (thread {}, at {}:{})",
|
||||
msg,
|
||||
name,
|
||||
|
@ -140,11 +146,12 @@ pub fn main() {
|
|||
location.line()
|
||||
);
|
||||
} else {
|
||||
println!("{} (thread {})", msg, name);
|
||||
let _ = writeln!(&mut stdout, "{} (thread {})", msg, name);
|
||||
}
|
||||
if env::var("RUST_BACKTRACE").is_ok() {
|
||||
backtrace::print();
|
||||
let _ = backtrace::print(&mut stdout);
|
||||
}
|
||||
drop(stdout);
|
||||
|
||||
error!("{}", msg);
|
||||
}));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue