Skip to content

Commit

Permalink
Also do so for tokio
Browse files Browse the repository at this point in the history
  • Loading branch information
passcod committed Nov 18, 2023
1 parent 7184c0f commit d8317d4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
3 changes: 1 addition & 2 deletions 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.
Expand Down
18 changes: 13 additions & 5 deletions 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.
Expand All @@ -25,9 +22,20 @@ impl CommandGroupBuilder<'_, tokio::process::Command> {
/// .expect("ls command failed to start");
/// ```
pub fn spawn(&mut self) -> std::io::Result<AsyncGroupChild> {
#[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)
Expand Down

0 comments on commit d8317d4

Please sign in to comment.