Skip to content

Instantly share code, notes, and snippets.

@rbradford
Created November 12, 2019 13:59
Show Gist options
  • Save rbradford/0c8dad0238785e07293a4288a8071ce5 to your computer and use it in GitHub Desktop.
Save rbradford/0c8dad0238785e07293a4288a8071ce5 to your computer and use it in GitHub Desktop.
diff --git a/devices/src/acpi.rs b/devices/src/acpi.rs
index 3165b504..e092e27d 100644
--- a/devices/src/acpi.rs
+++ b/devices/src/acpi.rs
@@ -37,6 +37,8 @@ impl BusDevice for AcpiShutdownDevice {
if let Err(e) = self.reset_evt.write(1) {
error!("Error triggering ACPI reset event: {}", e);
}
+
+ self.reset_evt.write(std::u64::MAX - 1).unwrap();
}
// The ACPI DSDT table specifies the S5 sleep state (shutdown) as value 5
const S5_SLEEP_VALUE: u8 = 5;
diff --git a/vmm/src/lib.rs b/vmm/src/lib.rs
index db176f4f..615cc511 100644
--- a/vmm/src/lib.rs
+++ b/vmm/src/lib.rs
@@ -183,7 +183,7 @@ impl Vmm {
fn new(api_evt: EventFd) -> Result<Self> {
let mut epoll = EpollContext::new().map_err(Error::Epoll)?;
let exit_evt = EventFd::new(EFD_NONBLOCK).map_err(Error::EventFdCreate)?;
- let reset_evt = EventFd::new(EFD_NONBLOCK).map_err(Error::EventFdCreate)?;
+ let reset_evt = EventFd::new(0).map_err(Error::EventFdCreate)?;
if unsafe { libc::isatty(libc::STDIN_FILENO as i32) } != 0 {
epoll.add_stdin().map_err(Error::Epoll)?;
@@ -357,8 +357,9 @@ impl Vmm {
}
EpollDispatch::Reset => {
// Consume the event.
- self.reset_evt.read().map_err(Error::EventFdRead)?;
- self.vm_reboot().map_err(Error::VmReboot)?;
+ if self.reset_evt.read().map_err(Error::EventFdRead)? == 1 {
+ self.vm_reboot().map_err(Error::VmReboot)?;
+ }
}
EpollDispatch::Stdin => {
if let Some(ref vm) = self.vm {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment