diff options
author | Jesse Luehrs <doy@tozt.net> | 2020-07-17 01:47:26 -0400 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2020-07-17 01:47:26 -0400 |
commit | 27aef41bd21bbef3156d337a019a109d9ea72a85 (patch) | |
tree | f114303d58351cbb6f8d17ca31d20b1220521445 /src/command.rs | |
parent | 6985d5dd288ebc665fa5b342d013fba656276a61 (diff) | |
download | pty-process-27aef41bd21bbef3156d337a019a109d9ea72a85.tar.gz pty-process-27aef41bd21bbef3156d337a019a109d9ea72a85.zip |
refactor to clean up the ioctl calls a bit
Diffstat (limited to 'src/command.rs')
-rw-r--r-- | src/command.rs | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/command.rs b/src/command.rs index 7377881..f7b1de8 100644 --- a/src/command.rs +++ b/src/command.rs @@ -43,7 +43,7 @@ impl Command for std::process::Command { unsafe { self.pre_exec(move || { nix::unistd::setsid().map_err(|e| e.as_errno().unwrap())?; - set_controlling_terminal(pts_fd, std::ptr::null()) + set_controlling_terminal(&pts) .map_err(|e| e.as_errno().unwrap())?; // in the parent, destructors will handle closing these file @@ -107,7 +107,16 @@ impl std::ops::DerefMut for Child { } nix::ioctl_write_ptr_bad!( - set_controlling_terminal, + set_controlling_terminal_unsafe, libc::TIOCSCTTY, libc::c_int ); + +fn set_controlling_terminal(fh: &std::fs::File) -> nix::Result<()> { + // safe because std::fs::File is required to contain a valid file + // descriptor + unsafe { + set_controlling_terminal_unsafe(fh.as_raw_fd(), std::ptr::null()) + } + .map(|_| ()) +} |