]> git.ipfire.org Git - thirdparty/qemu.git/commitdiff
Convert atexit users to exit_notifier
authorAnthony Liguori <aliguori@us.ibm.com>
Wed, 17 Mar 2010 22:59:26 +0000 (17:59 -0500)
committerAnthony Liguori <aliguori@us.ibm.com>
Fri, 19 Mar 2010 20:27:38 +0000 (15:27 -0500)
All of these users have global state so we really don't see a benefit from
exit_notifier.  However, using exit_notifier means that there's one less
justification for having global state in the first place.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
curses.c
hw/xen_backend.h
hw/xen_devconfig.c
hw/xen_domainbuild.c
hw/xen_machine_pv.c
qemu-char.c
sdl.c
vl.c

index 4b5beac1dc4d9170c8e75c45b5216235ee0c74fa..f9a983a8dd5f1ded53a16ec361bb2bcc4da40a9d 100644 (file)
--- a/curses.c
+++ b/curses.c
@@ -338,6 +338,7 @@ static void curses_keyboard_setup(void)
 void curses_display_init(DisplayState *ds, int full_screen)
 {
     DisplayChangeListener *dcl;
+    static Notifier notifier = { .notify = curses_atexit };
 #ifndef _WIN32
     if (!isatty(1)) {
         fprintf(stderr, "We need a terminal output\n");
@@ -347,7 +348,7 @@ void curses_display_init(DisplayState *ds, int full_screen)
 
     curses_setup();
     curses_keyboard_setup();
-    atexit(curses_atexit);
+    exit_notifier_add(&notifier);
 
 #ifndef _WIN32
 #if defined(SIGWINCH) && defined(KEY_RESIZE)
index f07f7d4224cb6e669370ad797e6419d35a823bf8..991a7b7d540ff9242a8634b680e5a7bb21e5a581 100644 (file)
@@ -97,7 +97,7 @@ extern struct XenDevOps xen_netdev_ops;       /* xen_nic.c         */
 void xen_init_display(int domid);
 
 /* configuration (aka xenbus setup) */
-void xen_config_cleanup(void);
+void xen_config_cleanup(Notifier *notifier);
 int xen_config_dev_blk(DriveInfo *disk);
 int xen_config_dev_nic(NICInfo *nic);
 int xen_config_dev_vfb(int vdev, const char *type);
index ea8f8c4c2df69277ff4c6b10723ec7d8f87caac9..028f47ecb59d3020ef4dc6a6c525ca50325f957f 100644 (file)
@@ -17,7 +17,7 @@ static void xen_config_cleanup_dir(char *dir)
     QTAILQ_INSERT_TAIL(&xs_cleanup, d, list);
 }
 
-void xen_config_cleanup(void)
+void xen_config_cleanup(Notifier *notifier)
 {
     struct xs_dirs *d;
 
index 2f59856f73c8d86861097388557662caeb66cdd5..b735ca453d91872c7c4d70c5191e277c2698627d 100644 (file)
@@ -211,7 +211,7 @@ static int xen_domain_watcher(void)
 }
 
 /* normal cleanup */
-static void xen_domain_cleanup(void)
+static void xen_domain_cleanup(Notifier *notifier)
 {
     char *dom;
 
@@ -232,6 +232,7 @@ int xen_domain_build_pv(const char *kernel, const char *ramdisk,
     unsigned int xenstore_port = 0, console_port = 0;
     unsigned long xenstore_mfn = 0, console_mfn = 0;
     int rc;
+    static Notifier exit_notifier = { .notify = xen_domain_cleanup };
 
     memcpy(uuid, qemu_uuid, sizeof(uuid));
     rc = xc_domain_create(xen_xc, ssidref, uuid, flags, &xen_domid);
@@ -240,7 +241,7 @@ int xen_domain_build_pv(const char *kernel, const char *ramdisk,
         goto err;
     }
     qemu_log("xen: created domain %d\n", xen_domid);
-    atexit(xen_domain_cleanup);
+    exit_notifier_add(&exit_notifier);
     if (xen_domain_watcher() == -1) {
         goto err;
     }
index 162f88db3326c113fea15d18a4254beb1c04166a..abfa02c951d353896a09838abc0c75ea6818d9f9 100644 (file)
@@ -42,6 +42,7 @@ static void xen_init_pv(ram_addr_t ram_size,
     CPUState *env;
     DriveInfo *dinfo;
     int i;
+    static Notifier exit_notifier = { .notify = xen_config_cleanup };
 
     /* Initialize a dummy CPU */
     if (cpu_model == NULL) {
@@ -105,7 +106,7 @@ static void xen_init_pv(ram_addr_t ram_size,
     }
 
     /* config cleanup hook */
-    atexit(xen_config_cleanup);
+    exit_notifier_addr(&exit_notifier);
 
     /* setup framebuffer */
     xen_init_display(xen_domid);
index a3d6e6496701f66ec30b509a32160c086c29f941..c02dfae43a57bbf36e238fc9f7925054738ae064 100644 (file)
@@ -713,9 +713,15 @@ static void term_exit(void)
     fcntl(0, F_SETFL, old_fd0_flags);
 }
 
+static void term_exit_notifier(Notifier *notifier)
+{
+    term_exit();
+}
+
 static void term_init(QemuOpts *opts)
 {
     struct termios tty;
+    static Notifier exit_notifier = { .notify = term_exit_notifier };
 
     tcgetattr (0, &tty);
     oldtty = tty;
@@ -735,8 +741,9 @@ static void term_init(QemuOpts *opts)
 
     tcsetattr (0, TCSANOW, &tty);
 
-    if (!term_atexit_done++)
-        atexit(term_exit);
+    if (!term_atexit_done++) {
+        exit_notifier_add(&exit_notifier);
+    }
 
     fcntl(0, F_SETFL, O_NONBLOCK);
 }
diff --git a/sdl.c b/sdl.c
index 16a48e92cb7f3ef3c92c12870d9359154cdd0301..8dc78cd9594cd49bad06ef49e2cf25563fed7aa6 100644 (file)
--- a/sdl.c
+++ b/sdl.c
@@ -827,7 +827,7 @@ static void sdl_mouse_define(int width, int height, int bpp,
         SDL_SetCursor(guest_sprite);
 }
 
-static void sdl_cleanup(void)
+static void sdl_cleanup(Notifier *notifier)
 {
     if (guest_sprite)
         SDL_FreeCursor(guest_sprite);
@@ -840,6 +840,7 @@ void sdl_display_init(DisplayState *ds, int full_screen, int no_frame)
     uint8_t data = 0;
     DisplayAllocator *da;
     const SDL_VideoInfo *vi;
+    static Notifier exit_notifier = { .notify = sdl_cleanup };
 
 #if defined(__APPLE__)
     /* always use generic keymaps */
@@ -892,7 +893,7 @@ void sdl_display_init(DisplayState *ds, int full_screen, int no_frame)
     sdl_cursor_hidden = SDL_CreateCursor(&data, &data, 8, 1, 0, 0);
     sdl_cursor_normal = SDL_GetCursor();
 
-    atexit(sdl_cleanup);
+    exit_notifier_add(&exit_notifier);
     if (full_screen) {
         gui_fullscreen = 1;
         gui_fullscreen_initial_grab = 1;
diff --git a/vl.c b/vl.c
index 183ec32a96fd48e0b5758668a1d913a39e8e020e..eda96aaa6c5f81a0046346471bbabe5fdeb56f1f 100644 (file)
--- a/vl.c
+++ b/vl.c
@@ -533,7 +533,7 @@ static void configure_rtc(QemuOpts *opts)
 }
 
 #ifdef _WIN32
-static void socket_cleanup(void)
+static void socket_cleanup(Notifier *obj)
 {
     WSACleanup();
 }
@@ -542,6 +542,7 @@ static int socket_init(void)
 {
     WSADATA Data;
     int ret, err;
+    static Notifier notifier = { .notify = socket_cleanup };
 
     ret = WSAStartup(MAKEWORD(2,2), &Data);
     if (ret != 0) {
@@ -549,7 +550,7 @@ static int socket_init(void)
         fprintf(stderr, "WSAStartup: %d\n", err);
         return -1;
     }
-    atexit(socket_cleanup);
+    exit_notifier_add(&notifier);
     return 0;
 }
 #endif
@@ -3768,6 +3769,8 @@ int main(int argc, char **argv, char **envp)
 
     error_set_progname(argv[0]);
 
+    exit_notifier_init();
+
     init_clocks();
 
     qemu_cache_utils_init(envp);