diff options
author | Jesse Luehrs <doy@tozt.net> | 2021-12-30 16:15:14 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2021-12-30 16:15:14 -0500 |
commit | 43e517cea6704f0d8424a88b13a1d40550c7e9ca (patch) | |
tree | d19bf1e3b3fa8b1e563ccb5c376a08505fb2e00e /src/command.rs | |
parent | b82bcb3aeb96fd3a867e6e717be3b9431faa70bd (diff) | |
download | pty-process-43e517cea6704f0d8424a88b13a1d40550c7e9ca.tar.gz pty-process-43e517cea6704f0d8424a88b13a1d40550c7e9ca.zip |
add spawn_pg
Diffstat (limited to 'src/command.rs')
-rw-r--r-- | src/command.rs | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/command.rs b/src/command.rs index cd1c8a3..c6dac9d 100644 --- a/src/command.rs +++ b/src/command.rs @@ -128,6 +128,30 @@ impl Command { Ok(self.inner.spawn()?) } + pub fn spawn_pg( + &mut self, + pg: Option<u32>, + ) -> crate::Result<async_process::Child> { + let mut set_process_group = crate::sys::set_process_group_child(pg); + // Safety: setpgid() is an async-signal-safe function and ioctl() is a + // raw syscall (which is inherently async-signal-safe). + if let Some(mut custom) = self.pre_exec.take() { + unsafe { + self.inner.pre_exec(move || { + set_process_group()?; + custom()?; + Ok(()) + }) + }; + } else { + unsafe { self.inner.pre_exec(set_process_group) }; + } + + let child = self.inner.spawn()?; + crate::sys::set_process_group_parent(child.id(), pg)?; + Ok(child) + } + pub fn uid(&mut self, id: u32) -> &mut Self { self.inner.uid(id); self |