summaryrefslogtreecommitdiffstats
path: root/ipc
diff options
context:
space:
mode:
authorIgor Matuszewski <igor@sequoia-pgp.org>2020-03-17 15:50:12 +0100
committerIgor Matuszewski <igor@sequoia-pgp.org>2020-03-18 17:52:41 +0100
commit27bb14f4145ed50ad474ef9e03116dd55138bc55 (patch)
tree2a2f59f15cd130da4e17d57b8bdcfec701c3558b /ipc
parentdbc0e90aa6b05c91a5c3f4210658f01598fb0dc6 (diff)
ipc: Streamline passing TCP fd as child stdin
Diffstat (limited to 'ipc')
-rw-r--r--ipc/src/lib.rs12
1 files changed, 3 insertions, 9 deletions
diff --git a/ipc/src/lib.rs b/ipc/src/lib.rs
index f6013484..6adcca98 100644
--- a/ipc/src/lib.rs
+++ b/ipc/src/lib.rs
@@ -62,7 +62,7 @@ use capnp_rpc::{RpcSystem, twoparty};
use capnp_rpc::rpc_twoparty_capnp::Side;
/* Unix-specific options. */
-use std::os::unix::io::{AsRawFd, FromRawFd};
+use std::os::unix::io::{IntoRawFd, FromRawFd};
use std::os::unix::fs::OpenOptionsExt;
/* XXX: Implement Windows support. */
@@ -244,12 +244,7 @@ impl Descriptor {
Ok(addr)
}
- fn fork(&self, l: TcpListener) -> Result<()> {
- // Convert to raw fd, then forget l so that it will not be
- // closed when it is dropped.
- let fd = l.as_raw_fd();
- ::std::mem::forget(l);
-
+ fn fork(&self, listener: TcpListener) -> Result<()> {
Command::new(&self.executable)
.arg("--home")
.arg(self.ctx.home())
@@ -257,8 +252,7 @@ impl Descriptor {
.arg(self.ctx.lib())
.arg("--ephemeral")
.arg(self.ctx.ephemeral().to_string())
- // l will be closed here if the exec fails.
- .stdin(unsafe { Stdio::from_raw_fd(fd) })
+ .stdin(unsafe { Stdio::from_raw_fd(listener.into_raw_fd()) })
.stdout(Stdio::null())
.stderr(Stdio::null())
.spawn()?;