From bdeb9c86f7adbb277715442bc341c360af6c03f8 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Wed, 29 Dec 2021 23:55:13 -0500 Subject: allow not passing the pt --- src/blocking/command.rs | 2 +- src/command.rs | 2 +- src/sys.rs | 8 +++++--- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/blocking/command.rs b/src/blocking/command.rs index 0ec55db..7f8d905 100644 --- a/src/blocking/command.rs +++ b/src/blocking/command.rs @@ -104,7 +104,7 @@ impl Command { pty: &crate::blocking::Pty, ) -> crate::Result { let (stdin, stdout, stderr, mut pre_exec) = - crate::sys::setup_subprocess(pty, pty.pts())?; + crate::sys::setup_subprocess(pty.pts(), Some(pty))?; self.inner.stdin(self.stdin.take().unwrap_or(stdin)); self.inner.stdout(self.stdout.take().unwrap_or(stdout)); diff --git a/src/command.rs b/src/command.rs index 171e764..dfe9684 100644 --- a/src/command.rs +++ b/src/command.rs @@ -104,7 +104,7 @@ impl Command { pty: &crate::Pty, ) -> crate::Result { let (stdin, stdout, stderr, mut pre_exec) = - crate::sys::setup_subprocess(pty, pty.pts())?; + crate::sys::setup_subprocess(pty.pts(), Some(pty))?; self.inner.stdin(self.stdin.take().unwrap_or(stdin)); self.inner.stdout(self.stdout.take().unwrap_or(stdout)); diff --git a/src/sys.rs b/src/sys.rs index 03a5428..ae789cd 100644 --- a/src/sys.rs +++ b/src/sys.rs @@ -39,15 +39,15 @@ pub fn set_term_size( } pub fn setup_subprocess( - pt: &impl std::os::unix::io::AsRawFd, pts: &impl std::os::unix::io::AsRawFd, + pt: Option<&impl std::os::unix::io::AsRawFd>, ) -> nix::Result<( std::process::Stdio, std::process::Stdio, std::process::Stdio, impl FnMut() -> std::io::Result<()>, )> { - let pt_fd = pt.as_raw_fd(); + let pt_fd = pt.map(std::os::unix::io::AsRawFd::as_raw_fd); let pts_fd = pts.as_raw_fd(); let stdin = nix::unistd::dup(pts_fd)?; @@ -70,7 +70,9 @@ pub fn setup_subprocess( // the child, we end by calling exec(), which doesn't call // destructors. - nix::unistd::close(pt_fd)?; + if let Some(pt_fd) = pt_fd { + nix::unistd::close(pt_fd)?; + } nix::unistd::close(pts_fd)?; // at this point, stdin/stdout/stderr have already been // reopened as fds 0/1/2 in the child, so we can (and should) -- cgit v1.2.3-54-g00ecf