mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-23 10:58:12 +08:00
Review
This commit is contained in:
@@ -5,15 +5,15 @@ use std::process::Command;
|
||||
use crate::frames::plane;
|
||||
|
||||
pub(crate) fn setup_command(command: &mut Command, #[cfg(feature = "accelerated_paint")] host_frame_fd: Option<std::os::fd::RawFd>) {
|
||||
let parent_pid = std::process::id() as libc::pid_t;
|
||||
let main_pid = std::process::id() as libc::pid_t;
|
||||
// SAFETY: the closure runs in the forked child before exec and only makes async-signal-safe calls
|
||||
unsafe {
|
||||
command.pre_exec(move || {
|
||||
// Tie the host's lifetime to the parent process
|
||||
// Tie the host's lifetime to the main process
|
||||
if libc::prctl(libc::PR_SET_PDEATHSIG, libc::SIGKILL) != 0 {
|
||||
return Err(std::io::Error::last_os_error());
|
||||
}
|
||||
if libc::getppid() != parent_pid {
|
||||
if libc::getppid() != main_pid {
|
||||
return Err(std::io::Error::other("main process died before PDEATHSIG was set"));
|
||||
}
|
||||
|
||||
|
||||
@@ -51,13 +51,13 @@ pub(crate) fn spawn_parent_watchdog(main_pid: u32) {
|
||||
loop {
|
||||
// SAFETY: getppid is always safe to call.
|
||||
if unsafe { libc::getppid() } as u32 != main_pid {
|
||||
tracing::warn!("Main process is gone, exiting CEF host");
|
||||
tracing::warn!("Parent process is gone, exiting...");
|
||||
std::process::exit(0);
|
||||
}
|
||||
std::thread::sleep(Duration::from_millis(500));
|
||||
}
|
||||
});
|
||||
if let Err(e) = result {
|
||||
tracing::error!("Failed to spawn the parent watchdog: {e}");
|
||||
tracing::error!("Failed to spawn parent watchdog: {e}");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user