aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-06-28 19:00:04 +0100
committerAleksey Kladov <[email protected]>2020-06-28 19:00:04 +0100
commit80ef52f0d5f9383e9f42ae77d9cb6b77483f11a6 (patch)
treeed2947cb9bff2f8d2d9b23b843dae38b7e4045d3
parent117cf0b85bc8022a939fe43054f64aaa35117dd9 (diff)
Make sure to join the child
-rw-r--r--crates/flycheck/src/lib.rs27
1 files changed, 25 insertions, 2 deletions
diff --git a/crates/flycheck/src/lib.rs b/crates/flycheck/src/lib.rs
index 92ec4f92e..9335098ff 100644
--- a/crates/flycheck/src/lib.rs
+++ b/crates/flycheck/src/lib.rs
@@ -5,8 +5,9 @@
5use std::{ 5use std::{
6 fmt, 6 fmt,
7 io::{self, BufReader}, 7 io::{self, BufReader},
8 ops,
8 path::PathBuf, 9 path::PathBuf,
9 process::{Command, Stdio}, 10 process::{self, Command, Stdio},
10 time::Duration, 11 time::Duration,
11}; 12};
12 13
@@ -236,8 +237,9 @@ fn run_cargo(
236 mut command: Command, 237 mut command: Command,
237 on_message: &mut dyn FnMut(cargo_metadata::Message) -> bool, 238 on_message: &mut dyn FnMut(cargo_metadata::Message) -> bool,
238) -> io::Result<()> { 239) -> io::Result<()> {
239 let mut child = 240 let child =
240 command.stdout(Stdio::piped()).stderr(Stdio::null()).stdin(Stdio::null()).spawn()?; 241 command.stdout(Stdio::piped()).stderr(Stdio::null()).stdin(Stdio::null()).spawn()?;
242 let mut child = ChildKiller(child);
241 243
242 // We manually read a line at a time, instead of using serde's 244 // We manually read a line at a time, instead of using serde's
243 // stream deserializers, because the deserializer cannot recover 245 // stream deserializers, because the deserializer cannot recover
@@ -283,3 +285,24 @@ fn run_cargo(
283 285
284 Ok(()) 286 Ok(())
285} 287}
288
289struct ChildKiller(process::Child);
290
291impl ops::Deref for ChildKiller {
292 type Target = process::Child;
293 fn deref(&self) -> &process::Child {
294 &self.0
295 }
296}
297
298impl ops::DerefMut for ChildKiller {
299 fn deref_mut(&mut self) -> &mut process::Child {
300 &mut self.0
301 }
302}
303
304impl Drop for ChildKiller {
305 fn drop(&mut self) {
306 let _ = self.0.kill();
307 }
308}