Index: ioemu/monitor.c
===================================================================
--- ioemu.orig/monitor.c	2007-05-03 19:01:49.000000000 +0100
+++ ioemu/monitor.c	2007-05-03 19:12:02.000000000 +0100
@@ -339,6 +339,7 @@
 
 static void do_quit(void)
 {
+    destroy_hvm_domain();
     exit(0);
 }
 
Index: ioemu/target-i386-dm/helper2.c
===================================================================
--- ioemu.orig/target-i386-dm/helper2.c	2007-05-03 19:12:00.000000000 +0100
+++ ioemu/target-i386-dm/helper2.c	2007-05-03 19:12:02.000000000 +0100
@@ -549,5 +549,26 @@
         /* Wait up to 10 msec. */
         main_loop_wait(10);
 
+    destroy_hvm_domain();
+
     return 0;
 }
+
+void destroy_hvm_domain(void)
+{
+    int xcHandle;
+    int sts;
+ 
+    xcHandle = xc_interface_open();
+    if (xcHandle < 0)
+        fprintf(logfile, "Cannot acquire xenctrl handle\n");
+    else {
+        sts = xc_domain_shutdown(xcHandle, domid, SHUTDOWN_poweroff);
+        if (sts != 0)
+            fprintf(logfile, "? xc_domain_shutdown failed to issue poweroff, "
+                    "sts %d, errno %d\n", sts, errno);
+        else
+            fprintf(logfile, "Issued domain %d poweroff\n", domid);
+        xc_interface_close(xcHandle);
+    }
+}
Index: ioemu/vl.h
===================================================================
--- ioemu.orig/vl.h	2007-05-03 19:12:00.000000000 +0100
+++ ioemu/vl.h	2007-05-03 19:12:02.000000000 +0100
@@ -1410,4 +1410,7 @@
 void kqemu_record_dump(void);
 
 extern char domain_name[];
+
+void destroy_hvm_domain(void);
+
 #endif /* VL_H */
