From 3b6304f706ef7eebc0b3b3f3a5093ec75448ee19 Mon Sep 17 00:00:00 2001 From: Anthony Liguori Date: Wed, 17 Mar 2010 17:44:48 -0500 Subject: [PATCH] Add exit notifiers Like atexit() but with state Signed-off-by: Anthony Liguori --- sysemu.h | 5 +++++ vl.c | 27 +++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/sysemu.h b/sysemu.h index 525efd13cb..bc33abfc9b 100644 --- a/sysemu.h +++ b/sysemu.h @@ -8,6 +8,7 @@ #include "qemu-timer.h" #include "qdict.h" #include "qerror.h" +#include "notify.h" #ifdef _WIN32 #include @@ -73,6 +74,10 @@ int qemu_savevm_state_complete(Monitor *mon, QEMUFile *f); void qemu_savevm_state_cancel(Monitor *mon, QEMUFile *f); int qemu_loadvm_state(QEMUFile *f); +void exit_notifier_add(Notifier *notifier); +void exit_notifier_remove(Notifier *notifier); + + #ifdef _WIN32 /* Polling handling */ diff --git a/vl.c b/vl.c index d69250ca26..183ec32a96 100644 --- a/vl.c +++ b/vl.c @@ -150,6 +150,7 @@ int main(int argc, char **argv) #include "qemu-option.h" #include "qemu-config.h" #include "qemu-objects.h" +#include "notify.h" #include "disas.h" @@ -553,6 +554,32 @@ static int socket_init(void) } #endif +/*********************/ +/* Exit notifiers */ +/*********************/ + +static NotifierList exit_notifiers = NOTIFIER_LIST_INITIALIZER(exit_notifiers); + +void exit_notifier_add(Notifier *notifier) +{ + notifier_list_add(&exit_notifiers, notifier); +} + +void exit_notifier_remove(Notifier *notifier) +{ + notifier_list_remove(&exit_notifiers, notifier); +} + +static void exit_notifier_notify(void) +{ + notifier_list_notify(&exit_notifiers); +} + +static void exit_notifier_init(void) +{ + atexit(exit_notifier_notify); +} + /***********************************************************/ /* Bluetooth support */ static int nb_hcis; -- 2.11.0