minidumper_child/
client.rsuse crate::Error;
use crash_handler::{make_crash_event, CrashContext, CrashEventResult, CrashHandler};
use minidumper::Client;
use std::{sync::Arc, time::Duration};
pub fn start(
socket_name: &str,
connect_timeout: u64,
#[allow(unused_variables)] server_pid: u32,
server_poll: u64,
) -> Result<(Arc<Client>, CrashHandler), Error> {
let mut wait_time = 0;
let client = loop {
match minidumper::Client::with_name(socket_name).map(Arc::new) {
Ok(client) => break client,
Err(e) => {
if wait_time < connect_timeout {
std::thread::sleep(Duration::from_millis(50));
wait_time += 50;
} else {
return Err(Error::from(e));
}
}
}
};
std::thread::spawn({
let client = client.clone();
move || loop {
std::thread::sleep(Duration::from_millis(server_poll));
if client.ping().is_err() {
break;
}
}
});
let handler = CrashHandler::attach(unsafe {
let client = client.clone();
make_crash_event(move |crash_context: &CrashContext| {
client.ping().ok();
CrashEventResult::Handled(client.request_dump(crash_context).is_ok())
})
})?;
#[cfg(target_os = "linux")]
handler.set_ptracer(Some(server_pid));
Ok((client, handler))
}