Add an atexit handler to remove the D-Bus socket
authorMike Gorse <mgorse@suse.com>
Mon, 14 Apr 2014 20:21:24 +0000 (15:21 -0500)
committerMike Gorse <mgorse@suse.com>
Mon, 14 Apr 2014 20:23:21 +0000 (15:23 -0500)
We should try not to leave stale sockets and their directories when exiting.
They are removed when calling atk_bridge_adaptor_cleanup, but gtk does not
currently call this function when exiting, and there is not a good place
to call it from gtk.

https://bugzilla.gnome.org/show_bug.cgi?id=684076

atk-adaptor/bridge.c

index aeabb9199468b017bd7daa913fa83c6089ddb6f3..2da29a71dbdf3e32aec09f105f43750bb8beab4b 100644 (file)
@@ -57,6 +57,7 @@ signal_filter (DBusConnection *bus, DBusMessage *message, void *user_data);
 SpiBridge *spi_global_app_data = NULL;
 
 static gboolean inited = FALSE;
+static gboolean atexit_added = FALSE;
 
 /*---------------------------------------------------------------------------*/
 
@@ -445,6 +446,27 @@ register_application (SpiBridge * app)
 
 /*---------------------------------------------------------------------------*/
 
+static void
+remove_socket ()
+{
+  if (!spi_global_app_data)
+    return;
+
+  if (spi_global_app_data->app_bus_addr)
+  {
+    unlink (spi_global_app_data->app_bus_addr);
+    g_free (spi_global_app_data->app_bus_addr);
+    spi_global_app_data->app_bus_addr = NULL;
+  }
+
+  if (spi_global_app_data->app_tmp_dir)
+  {
+    rmdir (spi_global_app_data->app_tmp_dir);
+    g_free (spi_global_app_data->app_tmp_dir);
+    spi_global_app_data->app_tmp_dir = NULL;
+  }
+}
+
 static void
 deregister_application (SpiBridge * app)
 {
@@ -466,19 +488,7 @@ deregister_application (SpiBridge * app)
   if (message)
     dbus_message_unref (message);
 
-  if (app->app_bus_addr)
-  {
-    unlink (app->app_bus_addr);
-    g_free (app->app_bus_addr);
-    app->app_bus_addr = NULL;
-  }
-
-  if (app->app_tmp_dir)
-  {
-    rmdir (app->app_tmp_dir);
-    g_free (app->app_tmp_dir);
-    app->app_tmp_dir = NULL;
-  }
+  remove_socket ();
 
   g_free (app->desktop_name);
   app->desktop_name = NULL;
@@ -1091,6 +1101,10 @@ atk_bridge_adaptor_init (gint * argc, gchar ** argv[])
   else
     get_registered_event_listeners (spi_global_app_data);
 
+  if (!atexit_added)
+    atexit (remove_socket);
+  atexit_added = TRUE;
+
   dbus_error_free (&error);
   return 0;
 }