()
| 98 | |
| 99 | #[cfg(target_os = "linux")] |
| 100 | fn install_linux_pdeathsig() -> Result<(), String> { |
| 101 | use nix::sys::signal::Signal; |
| 102 | use nix::unistd::getppid; |
| 103 | |
| 104 | // Race: if the parent already died between fork/exec and this call, |
| 105 | // `getppid()` now returns 1 and PR_SET_PDEATHSIG will never fire. |
| 106 | // Read the current parent first so we can detect that case and exit. |
| 107 | let original_ppid = getppid(); |
| 108 | if original_ppid == nix::unistd::Pid::from_raw(1) { |
| 109 | return Err("process was already orphaned before procguard armed".to_string()); |
| 110 | } |
| 111 | |
| 112 | nix::sys::prctl::set_pdeathsig(Signal::SIGKILL) |
| 113 | .map_err(|err| format!("prctl(PR_SET_PDEATHSIG) failed: {err}"))?; |
| 114 | |
| 115 | // Re-check after arming: the parent may have died between getppid() |
| 116 | // and prctl(). If so, PR_SET_PDEATHSIG missed its window. |
| 117 | if getppid() != original_ppid { |
| 118 | return Err("parent exited before procguard could arm".to_string()); |
| 119 | } |
| 120 | |
| 121 | Ok(()) |
| 122 | } |
| 123 | |
| 124 | #[cfg(any( |
| 125 | target_os = "macos", |
no outgoing calls
no test coverage detected