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/sys.rs | |
parent | b82bcb3aeb96fd3a867e6e717be3b9431faa70bd (diff) | |
download | pty-process-43e517cea6704f0d8424a88b13a1d40550c7e9ca.tar.gz pty-process-43e517cea6704f0d8424a88b13a1d40550c7e9ca.zip |
add spawn_pg
Diffstat (limited to 'src/sys.rs')
-rw-r--r-- | src/sys.rs | 26 |
1 files changed, 26 insertions, 0 deletions
@@ -76,6 +76,32 @@ pub fn session_leader( } } +pub fn set_process_group_child( + pg: Option<u32>, +) -> impl FnMut() -> std::io::Result<()> { + move || { + nix::unistd::setpgid( + nix::unistd::Pid::from_raw(0), + pg.map_or(nix::unistd::Pid::from_raw(0), |pid| { + nix::unistd::Pid::from_raw(pid.try_into().unwrap()) + }), + )?; + Ok(()) + } +} + +pub fn set_process_group_parent( + pid: u32, + pg: Option<u32>, +) -> nix::Result<()> { + nix::unistd::setpgid( + nix::unistd::Pid::from_raw(pid.try_into().unwrap()), + pg.map_or(nix::unistd::Pid::from_raw(0), |pid| { + nix::unistd::Pid::from_raw(pid.try_into().unwrap()) + }), + ) +} + fn set_controlling_terminal(fd: std::os::unix::io::RawFd) -> nix::Result<()> { // Safety: std::fs::File is required to contain a valid file descriptor unsafe { set_controlling_terminal_unsafe(fd, std::ptr::null()) } |