Last active
January 25, 2024 19:22
-
-
Save chantra/9ca275a8bacbae87776cffe1282deb15 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/qemu.rs b/src/qemu.rs | |
index b54d952..b8a7b81 100644 | |
--- a/src/qemu.rs | |
+++ b/src/qemu.rs | |
@@ -926,7 +926,13 @@ impl Qemu { | |
/// Boot the VM and connect to QGA | |
/// | |
/// Returns the child process and QGA wrapper on success, an error otherwise. | |
- fn boot_vm(&mut self) -> Result<(Child, QgaWrapper, Qmp<QmpUnixStream>)> { | |
+ fn boot_vm( | |
+ &mut self, | |
+ ) -> Result<( | |
+ scopeguard::ScopeGuard<Child, impl FnOnce(Child)>, | |
+ QgaWrapper, | |
+ Qmp<QmpUnixStream>, | |
+ )> { | |
let _ = self.updates.send(Output::BootStart); | |
let mut child = match self.process.spawn() { | |
Ok(c) => c, | |
@@ -986,7 +992,7 @@ impl Qemu { | |
let _ = self.updates.send(Output::BootEnd(Ok(()))); | |
- Ok((scopeguard::ScopeGuard::into_inner(child), qga, qmp)) | |
+ Ok((child, qga, qmp)) | |
} | |
/// Setup the VM | |
@@ -1021,7 +1027,7 @@ impl Qemu { | |
/// constructor. | |
pub fn run(mut self) { | |
// Start QEMU | |
- let (child, qga, mut qmp) = match self.boot_vm() { | |
+ let (mut child, qga, mut qmp) = match self.boot_vm() { | |
Ok((c, qga, qmp)) => (c, qga, qmp), | |
Err(e) => { | |
let _ = self.updates.send(Output::BootEnd(Err(e))); | |
@@ -1029,9 +1035,6 @@ impl Qemu { | |
} | |
}; | |
- // Ensure child is cleaned up even if we bail early | |
- let mut child = scopeguard::guard(child, Self::child_cleanup); | |
- | |
if let Err(e) = self.setup_vm(&qga) { | |
let _ = self.updates.send(Output::SetupEnd(Err(e))); | |
return; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment