aboutsummaryrefslogtreecommitdiff
path: root/vl.c
diff options
context:
space:
mode:
authorGerd Hoffmann <kraxel@redhat.com>2010-06-04 14:08:07 +0200
committerAnthony Liguori <aliguori@us.ibm.com>2010-06-14 15:46:28 -0500
commitfd42deeb4cb42f90084046e3ebdb4383953195e3 (patch)
tree671123e5db9674ce1950cd972c42b39da1408c71 /vl.c
parent4cf3e6f3d85492f20a773dd6c9068ab89ba24a18 (diff)
Add exit notifiers.
Hook up any cleanup work which needs to be done here. Advantages over using atexit(3): (1) You get passed in a pointer to the notifier. If you embed that into your state struct you can use container_of() to get get your state info. (2) You can unregister, say when un-plugging a device. [ v2: move code out of #ifndef _WIN32 ] Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'vl.c')
-rw-r--r--vl.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/vl.c b/vl.c
index df18198a1e..e5e43b3593 100644
--- a/vl.c
+++ b/vl.c
@@ -234,6 +234,9 @@ uint8_t qemu_uuid[16];
static QEMUBootSetHandler *boot_set_handler;
static void *boot_set_opaque;
+static NotifierList exit_notifiers =
+ NOTIFIER_LIST_INITIALIZER(exit_notifiers);
+
int kvm_allowed = 0;
uint32_t xen_domid;
enum xen_mode xen_mode = XEN_EMULATE;
@@ -1740,6 +1743,21 @@ static int debugcon_parse(const char *devname)
return 0;
}
+void qemu_add_exit_notifier(Notifier *notify)
+{
+ notifier_list_add(&exit_notifiers, notify);
+}
+
+void qemu_remove_exit_notifier(Notifier *notify)
+{
+ notifier_list_remove(&exit_notifiers, notify);
+}
+
+static void qemu_run_exit_notifiers(void)
+{
+ notifier_list_notify(&exit_notifiers);
+}
+
static const QEMUOption *lookup_opt(int argc, char **argv,
const char **poptarg, int *poptind)
{
@@ -1804,6 +1822,7 @@ int main(int argc, char **argv, char **envp)
int show_vnc_port = 0;
int defconfig = 1;
+ atexit(qemu_run_exit_notifiers);
error_set_progname(argv[0]);
init_clocks();