diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2018-01-10 12:16:34 +0100 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2018-01-10 12:45:18 +0100 |
commit | 5e678b11e9150f2f9728b1641e36f16ec7c8c3ef (patch) | |
tree | c38cc5bfa1b58c2e43b745f595d5124646dc5385 /net | |
parent | 9a2228ef3898fb5d1a45cb4b4d5fa1d7f8ce5bc4 (diff) |
net: Fix a race condition.
- Previously, the TcpListener 'l' that is handed to the child
process via conversion to a raw filedescriptor was closed when
being dropped. This lead to a small chance of closing the next
TcpListener, resulting in spurious failures when falling back to
the in-process server.
Diffstat (limited to 'net')
-rw-r--r-- | net/src/ipc.rs | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/net/src/ipc.rs b/net/src/ipc.rs index c67b049b..fef222ad 100644 --- a/net/src/ipc.rs +++ b/net/src/ipc.rs @@ -183,8 +183,14 @@ impl Descriptor { } fn fork(&self, l: TcpListener) -> io::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); + Command::new(&self.executable.clone().into_os_string()) - .stdin(unsafe { Stdio::from_raw_fd(l.as_raw_fd()) }) + // l will be closed here if the exec fails. + .stdin(unsafe { Stdio::from_raw_fd(fd) }) .spawn()?; Ok(()) } |