From 24d2764600c9aee479095a0577ffb8ec69ec7e66 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Mon, 22 Feb 2021 22:34:16 -0500 Subject: a bit more logic inversion --- src/command/std.rs | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) (limited to 'src/command/std.rs') diff --git a/src/command/std.rs b/src/command/std.rs index 0f3bef1..b331fc0 100644 --- a/src/command/std.rs +++ b/src/command/std.rs @@ -1,20 +1,15 @@ -use crate::error::*; - -use std::os::unix::io::{AsRawFd as _, FromRawFd as _}; +use std::os::unix::io::FromRawFd as _; use std::os::unix::process::CommandExt as _; -impl super::Command for std::process::Command { +impl super::CommandImpl for std::process::Command { type Child = std::process::Child; - fn spawn_pty( + fn std_fds( &mut self, - size: Option<&crate::pty::Size>, - ) -> Result> { - let (pty, pts, stdin, stdout, stderr) = super::setup_pty(size)?; - - let pt_fd = pty.pt().as_raw_fd(); - let pts_fd = pts.as_raw_fd(); - + stdin: ::std::os::unix::io::RawFd, + stdout: ::std::os::unix::io::RawFd, + stderr: ::std::os::unix::io::RawFd, + ) { // safe because the fds are valid (otherwise pty.pts() or dup() would // have returned an Err and we would have exited early) and are not // owned by any other structure (since dup() returns a fresh copy of @@ -22,18 +17,21 @@ impl super::Command for std::process::Command { self.stdin(unsafe { std::process::Stdio::from_raw_fd(stdin) }) .stdout(unsafe { std::process::Stdio::from_raw_fd(stdout) }) .stderr(unsafe { std::process::Stdio::from_raw_fd(stderr) }); + } + fn pre_exec_impl(&mut self, f: F) + where + F: FnMut() -> ::std::io::Result<()> + Send + Sync + 'static, + { // safe because setsid() and close() are async-signal-safe functions // and ioctl() is a raw syscall (which is inherently // async-signal-safe). unsafe { - self.pre_exec(move || { - super::pre_exec(pt_fd, pts_fd, stdin, stdout, stderr) - }); + self.pre_exec(f); } + } - let child = self.spawn().map_err(Error::Spawn)?; - - Ok(super::Child { child, pty }) + fn spawn_impl(&mut self) -> ::std::io::Result { + self.spawn() } } -- cgit v1.2.3-54-g00ecf