aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2021-12-29 23:55:13 -0500
committerJesse Luehrs <doy@tozt.net>2021-12-29 23:55:13 -0500
commitbdeb9c86f7adbb277715442bc341c360af6c03f8 (patch)
tree942e0d99b77dfba770ca1c95d203b0d6efdbcb4d
parentf1779c4549c88e7996031b7211a556e8e4b54963 (diff)
downloadpty-process-bdeb9c86f7adbb277715442bc341c360af6c03f8.tar.gz
pty-process-bdeb9c86f7adbb277715442bc341c360af6c03f8.zip
allow not passing the pt
-rw-r--r--src/blocking/command.rs2
-rw-r--r--src/command.rs2
-rw-r--r--src/sys.rs8
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<std::process::Child> {
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<async_process::Child> {
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)