Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try to avoid panicking during I/O in the signal and panic handlers. #25662

Merged
merged 1 commit into from Jan 31, 2020
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -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,20 +134,24 @@ 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,
location.file(),
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);
}));
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.