提交 1d445817 authored 作者: Serhij S's avatar Serhij S

modern panic info

上级 4c99c3ca
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
#![deny(missing_docs)] #![deny(missing_docs)]
use core::{fmt, num}; use core::{fmt, num};
use std::io::Write; use std::io::Write;
use std::panic::PanicInfo; use std::panic::PanicHookInfo;
use std::sync::atomic::{self, AtomicBool, Ordering}; use std::sync::atomic::{self, AtomicBool, Ordering};
use std::{env, sync::Arc, time::Duration}; use std::{env, sync::Arc, time::Duration};
...@@ -374,7 +374,7 @@ static PANIC_PREVENT: atomic::AtomicI32 = atomic::AtomicI32::new(0); ...@@ -374,7 +374,7 @@ static PANIC_PREVENT: atomic::AtomicI32 = atomic::AtomicI32::new(0);
/// Sets panic handler to immediately kill the process and its childs with SIGKILL. The process is /// Sets panic handler to immediately kill the process and its childs with SIGKILL. The process is
/// killed when panic happens in ANY thread /// killed when panic happens in ANY thread
pub fn setup_panic() { pub fn setup_panic() {
std::panic::set_hook(Box::new(move |info: &PanicInfo| { std::panic::set_hook(Box::new(move |info| {
panic(info); panic(info);
})); }));
} }
...@@ -393,7 +393,7 @@ pub fn allow_panic_suicide() { ...@@ -393,7 +393,7 @@ pub fn allow_panic_suicide() {
PANIC_PREVENT.store(0, atomic::Ordering::SeqCst); PANIC_PREVENT.store(0, atomic::Ordering::SeqCst);
} }
fn panic(info: &PanicInfo) -> ! { fn panic(info: &PanicHookInfo) -> ! {
eprintln!("{}", info.to_string().red().bold()); eprintln!("{}", info.to_string().red().bold());
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
{ {
...@@ -444,7 +444,7 @@ pub fn reload_executable() -> Result<()> { ...@@ -444,7 +444,7 @@ pub fn reload_executable() -> Result<()> {
.trim_end_matches(" (deleted)") .trim_end_matches(" (deleted)")
.to_owned(); .to_owned();
current_exe = current_exe.with_file_name(fname); current_exe = current_exe.with_file_name(fname);
std::os::unix::process::CommandExt::exec(&mut std::process::Command::new(current_exe)); let _ = std::os::unix::process::CommandExt::exec(&mut std::process::Command::new(current_exe));
Ok(()) Ok(())
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论