aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2021-02-22 22:47:20 -0500
committerJesse Luehrs <doy@tozt.net>2021-02-22 22:47:20 -0500
commitacb3681ee251599af194c8555344edc65750ef14 (patch)
tree00232dfa7f3138dfb28eba4b0ee8f577bc5f00dc
parent24d2764600c9aee479095a0577ffb8ec69ec7e66 (diff)
downloadpty-process-acb3681ee251599af194c8555344edc65750ef14.tar.gz
pty-process-acb3681ee251599af194c8555344edc65750ef14.zip
remove a bit more duplication
-rw-r--r--src/command.rs11
-rw-r--r--src/command/async_process.rs9
-rw-r--r--src/command/std.rs9
-rw-r--r--src/command/tokio.rs9
4 files changed, 14 insertions, 24 deletions
diff --git a/src/command.rs b/src/command.rs
index ca4a67b..0b53626 100644
--- a/src/command.rs
+++ b/src/command.rs
@@ -34,7 +34,8 @@ where
let pts_fd = pts.as_raw_fd();
self.std_fds(stdin, stdout, stderr);
- self.pre_exec_impl(move || {
+
+ let pre_exec = move || {
nix::unistd::setsid().map_err(|e| e.as_errno().unwrap())?;
set_controlling_terminal(pts_fd)
.map_err(|e| e.as_errno().unwrap())?;
@@ -56,7 +57,11 @@ where
nix::unistd::close(stderr).map_err(|e| e.as_errno().unwrap())?;
Ok(())
- });
+ };
+ // 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_impl(pre_exec) };
let child = self.spawn_impl().map_err(Error::Spawn)?;
@@ -103,7 +108,7 @@ pub trait CommandImpl {
stdout: ::std::os::unix::io::RawFd,
stderr: ::std::os::unix::io::RawFd,
);
- fn pre_exec_impl<F>(&mut self, f: F)
+ unsafe fn pre_exec_impl<F>(&mut self, f: F)
where
F: FnMut() -> ::std::io::Result<()> + Send + Sync + 'static;
fn spawn_impl(&mut self) -> ::std::io::Result<Self::Child>;
diff --git a/src/command/async_process.rs b/src/command/async_process.rs
index 0b5ceda..4c453e6 100644
--- a/src/command/async_process.rs
+++ b/src/command/async_process.rs
@@ -19,16 +19,11 @@ impl super::CommandImpl for async_process::Command {
.stderr(unsafe { std::process::Stdio::from_raw_fd(stderr) });
}
- fn pre_exec_impl<F>(&mut self, f: F)
+ unsafe fn pre_exec_impl<F>(&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(f);
- }
+ self.pre_exec(f);
}
fn spawn_impl(&mut self) -> ::std::io::Result<Self::Child> {
diff --git a/src/command/std.rs b/src/command/std.rs
index b331fc0..3287834 100644
--- a/src/command/std.rs
+++ b/src/command/std.rs
@@ -19,16 +19,11 @@ impl super::CommandImpl for std::process::Command {
.stderr(unsafe { std::process::Stdio::from_raw_fd(stderr) });
}
- fn pre_exec_impl<F>(&mut self, f: F)
+ unsafe fn pre_exec_impl<F>(&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(f);
- }
+ self.pre_exec(f);
}
fn spawn_impl(&mut self) -> ::std::io::Result<Self::Child> {
diff --git a/src/command/tokio.rs b/src/command/tokio.rs
index 338bc08..60dfb56 100644
--- a/src/command/tokio.rs
+++ b/src/command/tokio.rs
@@ -18,16 +18,11 @@ impl super::CommandImpl for tokio::process::Command {
.stderr(unsafe { std::process::Stdio::from_raw_fd(stderr) });
}
- fn pre_exec_impl<F>(&mut self, f: F)
+ unsafe fn pre_exec_impl<F>(&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(f);
- }
+ self.pre_exec(f);
}
fn spawn_impl(&mut self) -> ::std::io::Result<Self::Child> {