Index: ioemu/monitor.c
===================================================================
--- ioemu.orig/monitor.c	2006-08-17 19:37:36.489509621 +0100
+++ ioemu/monitor.c	2006-08-17 19:49:44.491850141 +0100
@@ -308,6 +308,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	2006-08-17 19:49:40.116333768 +0100
+++ ioemu/target-i386-dm/helper2.c	2006-08-17 19:49:44.491850141 +0100
@@ -488,5 +488,25 @@
             xc_evtchn_notify(xce_handle, ioreq_local_port[send_vcpu]);
         }
     }
+    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	2006-08-17 19:49:40.120333326 +0100
+++ ioemu/vl.h	2006-08-17 19:49:44.492850031 +0100
@@ -1190,4 +1190,7 @@
 void kqemu_record_dump(void);
 
 extern char domain_name[];
+
+void destroy_hvm_domain(void);
+
 #endif /* VL_H */
