From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=56658 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OKTJS-0008UN-D0 for qemu-devel@nongnu.org; Fri, 04 Jun 2010 05:35:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OKTJR-0000np-29 for qemu-devel@nongnu.org; Fri, 04 Jun 2010 05:35:38 -0400 Received: from mx1.redhat.com ([209.132.183.28]:32893) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OKTJQ-0000ne-Qj for qemu-devel@nongnu.org; Fri, 04 Jun 2010 05:35:37 -0400 Received: from int-mx03.intmail.prod.int.phx2.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o549ZZRc027480 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 4 Jun 2010 05:35:35 -0400 From: Gerd Hoffmann Date: Fri, 4 Jun 2010 11:35:32 +0200 Message-Id: <1275644132-22176-1-git-send-email-kraxel@redhat.com> Subject: [Qemu-devel] [PATCH] Add exit notifiers. List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Gerd Hoffmann 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. Signed-off-by: Gerd Hoffmann --- roms/seabios | 2 +- sysemu.h | 4 ++++ vl.c | 19 +++++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletions(-) diff --git a/roms/seabios b/roms/seabios index 8f469b9..7d09d0e 160000 --- a/roms/seabios +++ b/roms/seabios @@ -1 +1 @@ -Subproject commit 8f469b9676127ba6bb52609d89ec774e61db0ee1 +Subproject commit 7d09d0e3ba11310e973d4302c7fcc3fc2184e04c diff --git a/sysemu.h b/sysemu.h index fd9dd9d..140b7ff 100644 --- a/sysemu.h +++ b/sysemu.h @@ -6,6 +6,7 @@ #include "qemu-option.h" #include "qemu-queue.h" #include "qemu-timer.h" +#include "notify.h" #ifdef _WIN32 #include @@ -51,6 +52,9 @@ int qemu_powerdown_requested(void); extern qemu_irq qemu_system_powerdown; void qemu_system_reset(void); +void qemu_add_exit_notifier(Notifier *notify); +void qemu_remove_exit_notifier(Notifier *notify); + void do_savevm(Monitor *mon, const QDict *qdict); int load_vmstate(const char *name); void do_delvm(Monitor *mon, const QDict *qdict); diff --git a/vl.c b/vl.c index ac1a998..1577566 100644 --- a/vl.c +++ b/vl.c @@ -243,6 +243,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; @@ -2127,6 +2130,21 @@ static BOOL WINAPI qemu_ctrl_handler(DWORD type) #ifndef _WIN32 +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 void termsig_handler(int signal) { qemu_system_shutdown_request(); @@ -2583,6 +2601,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(); -- 1.6.6.1