fix: Support Spawning Processes on macOS

Allow using pipe on macOS when attempting to spawn a process.
This commit is contained in:
Vadim Khitrin 2025-03-08 00:43:13 +02:00 committed by Michael Murphy
parent a234a45ea6
commit 64ddcb3bf2

View file

@ -23,15 +23,25 @@ async fn read_from_pipe(read: OwnedFd) -> Option<u32> {
/// Performs a double fork with setsid to spawn and detach a command.
pub async fn spawn(mut command: Command) -> Option<u32> {
// NOTE: Windows platform is not supported
command
.stdin(Stdio::null())
.stdout(Stdio::null())
.stderr(Stdio::null());
// Handle Linux
#[cfg(target_os = "linux")]
let Ok((read, write)) = rustix::pipe::pipe_with(rustix::pipe::PipeFlags::CLOEXEC) else {
return None;
};
// Handle macOS
#[cfg(target_os = "macos")]
let Ok((read, write)) = rustix::pipe::pipe() else {
return None;
};
match unsafe { libc::fork() } {
// Parent process
1.. => {