diff options
author | Jesse Luehrs <doy@tozt.net> | 2021-12-28 03:33:52 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2021-12-28 05:28:28 -0500 |
commit | f8780ca1e76286688b74d8a6c64d5fadf3cfd2a1 (patch) | |
tree | b1e0fe6a378f3a8810e0332ca572a86185fd556c /src/command | |
parent | b181b63a69d5db78769c1c3723a9940f66491466 (diff) | |
download | pty-process-f8780ca1e76286688b74d8a6c64d5fadf3cfd2a1.tar.gz pty-process-f8780ca1e76286688b74d8a6c64d5fadf3cfd2a1.zip |
wip
Diffstat (limited to 'src/command')
-rw-r--r-- | src/command/async_process.rs | 33 | ||||
-rw-r--r-- | src/command/std.rs | 33 | ||||
-rw-r--r-- | src/command/tokio.rs | 34 |
3 files changed, 48 insertions, 52 deletions
diff --git a/src/command/async_process.rs b/src/command/async_process.rs index 4a1d042..a0aaa47 100644 --- a/src/command/async_process.rs +++ b/src/command/async_process.rs @@ -1,23 +1,22 @@ use async_process::unix::CommandExt as _; -use std::os::unix::io::FromRawFd as _; impl super::Impl for async_process::Command { type Child = async_process::Child; - type Pty = crate::pty::async_io::Pty; - fn std_fds( - &mut self, - 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 - // the file descriptor), allowing from_raw_fd to take ownership of it. - 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 new_impl(program: &::std::ffi::OsStr) -> Self { + Self::new(program) + } + + fn stdin_impl(&mut self, cfg: ::std::process::Stdio) { + self.stdin(cfg); + } + + fn stdout_impl(&mut self, cfg: ::std::process::Stdio) { + self.stdout(cfg); + } + + fn stderr_impl(&mut self, cfg: ::std::process::Stdio) { + self.stderr(cfg); } unsafe fn pre_exec_impl<F>(&mut self, f: F) @@ -27,7 +26,7 @@ impl super::Impl for async_process::Command { self.pre_exec(f); } - fn spawn_impl(&mut self) -> ::std::io::Result<Self::Child> { - self.spawn() + fn spawn_impl(&mut self) -> crate::Result<Self::Child> { + self.spawn().map_err(crate::error::spawn) } } diff --git a/src/command/std.rs b/src/command/std.rs index 5c08808..2a89db5 100644 --- a/src/command/std.rs +++ b/src/command/std.rs @@ -1,23 +1,22 @@ -use std::os::unix::io::FromRawFd as _; use std::os::unix::process::CommandExt as _; impl super::Impl for std::process::Command { type Child = std::process::Child; - type Pty = crate::pty::std::Pty; - fn std_fds( - &mut self, - 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 - // the file descriptor), allowing from_raw_fd to take ownership of it. - 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 new_impl(program: &::std::ffi::OsStr) -> Self { + Self::new(program) + } + + fn stdin_impl(&mut self, cfg: ::std::process::Stdio) { + self.stdin(cfg); + } + + fn stdout_impl(&mut self, cfg: ::std::process::Stdio) { + self.stdout(cfg); + } + + fn stderr_impl(&mut self, cfg: ::std::process::Stdio) { + self.stderr(cfg); } unsafe fn pre_exec_impl<F>(&mut self, f: F) @@ -27,7 +26,7 @@ impl super::Impl for std::process::Command { self.pre_exec(f); } - fn spawn_impl(&mut self) -> ::std::io::Result<Self::Child> { - self.spawn() + fn spawn_impl(&mut self) -> crate::Result<Self::Child> { + self.spawn().map_err(crate::error::spawn) } } diff --git a/src/command/tokio.rs b/src/command/tokio.rs index 58d2c26..c63b18a 100644 --- a/src/command/tokio.rs +++ b/src/command/tokio.rs @@ -1,22 +1,20 @@ -use std::os::unix::io::FromRawFd as _; - impl super::Impl for tokio::process::Command { type Child = tokio::process::Child; - type Pty = crate::pty::tokio::Pty; - fn std_fds( - &mut self, - 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 - // the file descriptor), allowing from_raw_fd to take ownership of it. - 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 new_impl(program: &::std::ffi::OsStr) -> Self { + Self::new(program) + } + + fn stdin_impl(&mut self, cfg: ::std::process::Stdio) { + self.stdin(cfg); + } + + fn stdout_impl(&mut self, cfg: ::std::process::Stdio) { + self.stdout(cfg); + } + + fn stderr_impl(&mut self, cfg: ::std::process::Stdio) { + self.stderr(cfg); } unsafe fn pre_exec_impl<F>(&mut self, f: F) @@ -26,7 +24,7 @@ impl super::Impl for tokio::process::Command { self.pre_exec(f); } - fn spawn_impl(&mut self) -> ::std::io::Result<Self::Child> { - self.spawn() + fn spawn_impl(&mut self) -> crate::Result<Self::Child> { + self.spawn().map_err(crate::error::spawn) } } |