Closed
Description
The before_exec method should be marked unsafe because after a fork from a multi-threaded process, POSIX allows only allows async-signal-safe functions to be called. Otherwise, the result is undefined behavior.
The only way to enforce this in Rust is to mark the function as unsafe.
So to be clear, this should not compile:
use std::process::Command;
use std::os::unix::process::CommandExt;
fn main() {
let status = Command::new("sh")
.arg("-c")
.arg("echo world")
.before_exec(|| { println!("hello"); Ok(()) })
.status().unwrap();
println!("status: {}", status);
}