diff --git a/src/stdlib/unix.rs b/src/stdlib/unix.rs index 20b564a..66bd6a9 100644 --- a/src/stdlib/unix.rs +++ b/src/stdlib/unix.rs @@ -1,7 +1,6 @@ -use std::{io::Error, os::unix::process::CommandExt, process::Command}; +use std::{os::unix::process::CommandExt, process::Command}; use crate::{builder::CommandGroupBuilder, GroupChild}; -use nix::unistd::setsid; impl CommandGroupBuilder<'_, Command> { /// Executes the command as a child process group, returning a handle to it. diff --git a/src/tokio/unix.rs b/src/tokio/unix.rs index 587db2f..f073b43 100644 --- a/src/tokio/unix.rs +++ b/src/tokio/unix.rs @@ -1,8 +1,5 @@ -use std::io::Error; - use crate::builder::CommandGroupBuilder; use crate::AsyncGroupChild; -use nix::unistd::setsid; impl CommandGroupBuilder<'_, tokio::process::Command> { /// Executes the command as a child process group, returning a handle to it. @@ -25,9 +22,20 @@ impl CommandGroupBuilder<'_, tokio::process::Command> { /// .expect("ls command failed to start"); /// ``` pub fn spawn(&mut self) -> std::io::Result { + #[cfg(tokio_unstable)] + { + self.command.process_group(0); + } + + #[cfg(not(tokio_unstable))] unsafe { - self.command - .pre_exec(|| setsid().map_err(Error::from).map(|_| ())); + use nix::unistd::{setpgid, Pid}; + use std::io::Error; + self.command.pre_exec(|| { + setpgid(Pid::this(), Pid::from_raw(0)) + .map_err(Error::from) + .map(|_| ()) + }); } self.command.spawn().map(AsyncGroupChild::new)