Properly implement Drop for JodGroupChild

This commit is contained in:
Lukas Wirth 2022-11-24 21:30:15 +01:00
parent 81d26e730e
commit c8b6fef70f

View File

@ -360,13 +360,20 @@ impl FlycheckActor {
} }
} }
struct JodChild(GroupChild); struct JodGroupChild(GroupChild);
impl Drop for JodGroupChild {
fn drop(&mut self) {
_ = self.0.kill();
_ = self.0.wait();
}
}
/// A handle to a cargo process used for fly-checking. /// A handle to a cargo process used for fly-checking.
struct CargoHandle { struct CargoHandle {
/// The handle to the actual cargo process. As we cannot cancel directly from with /// The handle to the actual cargo process. As we cannot cancel directly from with
/// a read syscall dropping and therefore terminating the process is our best option. /// a read syscall dropping and therefore terminating the process is our best option.
child: JodChild, child: JodGroupChild,
thread: jod_thread::JoinHandle<io::Result<(bool, String)>>, thread: jod_thread::JoinHandle<io::Result<(bool, String)>>,
receiver: Receiver<CargoMessage>, receiver: Receiver<CargoMessage>,
} }
@ -374,7 +381,7 @@ struct CargoHandle {
impl CargoHandle { impl CargoHandle {
fn spawn(mut command: Command) -> std::io::Result<CargoHandle> { fn spawn(mut command: Command) -> std::io::Result<CargoHandle> {
command.stdout(Stdio::piped()).stderr(Stdio::piped()).stdin(Stdio::null()); command.stdout(Stdio::piped()).stderr(Stdio::piped()).stdin(Stdio::null());
let mut child = command.group_spawn().map(JodChild)?; let mut child = command.group_spawn().map(JodGroupChild)?;
let stdout = child.0.inner().stdout.take().unwrap(); let stdout = child.0.inner().stdout.take().unwrap();
let stderr = child.0.inner().stderr.take().unwrap(); let stderr = child.0.inner().stderr.take().unwrap();