Fix missing NULL argument to g_strconcat.
[platform/upstream/at-spi2-core.git] / registryd / registry-main.c
index 51cf7d1..083de19 100644 (file)
@@ -26,6 +26,7 @@
 #include <string.h>
 #include <glib.h>
 #include <stdio.h>
+#include <dlfcn.h>
 
 #include <dbus/dbus.h>
 #include <dbus/dbus-glib.h>
@@ -34,9 +35,9 @@
 #include "registry.h"
 #include "deviceeventcontroller.h"
 
-#if !defined ATSPI_INTROSPECTION_PATH
-    #error "No introspection XML directory defined"
-#endif
+#define CORBA_GCONF_KEY  "/desktop/gnome/interface/at-spi-corba"
+
+static gboolean need_to_quit ();
 
 static GMainLoop *mainloop;
 static gchar *dbus_name = NULL;
@@ -87,8 +88,36 @@ session_manager_connect (void)
 }
 
 static void
+kill_accessibility_bus ()
+{
+  FILE *fp;
+  const char *home;
+  char *name;
+  int pid;
+
+  home = getenv ("HOME");
+  if (!home)
+    return;
+  name = g_strconcat (home, "/", ".atspi-dbus-bus.pid", NULL);
+  if (!name)
+    return;
+
+  fp = fopen (name, "r");
+  if (fp)
+  {
+    if (fscanf (fp, "%d", &pid) == 1)
+    {
+      kill (&pid, SIGTERM);
+    }
+    fclose (fp);
+  }
+  g_free (name);
+}
+
+static void
 stop_cb (gpointer data)
 {
+        kill_accessibility_bus ();
         g_main_loop_quit (mainloop);
 }
 
@@ -122,6 +151,7 @@ query_end_session_cb (guint flags, gpointer data)
 static void
 end_session_cb (guint flags, gpointer data)
 {
+        kill_accessibility_bus ();
         end_session_response (TRUE, NULL);
         g_main_loop_quit (mainloop);
 }
@@ -259,6 +289,7 @@ spi_get_bus (void)
      else
      {
         bus = dbus_connection_open (data, &error);
+        XFree (data);
          if (!bus)
          {
              g_error ("AT-SPI: Couldn't connect to bus: %s\n", error.message);
@@ -266,21 +297,24 @@ spi_get_bus (void)
         else
          {
             if (!dbus_bus_register (bus, &error))
-                g_error ("AT-SPI: Couldn't register with bus: %s\n");
+                g_error ("AT-SPI: Couldn't register with bus: %s\n", error.message);
          } 
      }
 
+  XCloseDisplay (bridge_display);
      return bus;
 }
 
 /*---------------------------------------------------------------------------*/
 
+typedef GObject *(*gconf_client_get_default_t) ();
+typedef gboolean (*gconf_client_get_bool_t)(GObject *, const char *, void *);
+
 int
 main (int argc, char **argv)
 {
   SpiRegistry *registry;
   SpiDEController *dec;
-  gchar *introspection_directory;
 
   DBusConnection *bus = NULL;
 
@@ -290,6 +324,9 @@ main (int argc, char **argv)
   DBusError error;
   int ret;
 
+  if (need_to_quit ())
+    return 0;
+
   g_type_init();
 
   /*Parse command options*/
@@ -323,11 +360,6 @@ main (int argc, char **argv)
       g_print ("SpiRegistry daemon is running with well-known name - %s\n", dbus_name);
     }
 
-  /* Get D-Bus introspection directory */
-  introspection_directory = (char *) g_getenv("ATSPI_INTROSPECTION_PATH");
-  if (introspection_directory == NULL)
-      introspection_directory = ATSPI_INTROSPECTION_PATH;
-
   registry = spi_registry_new (bus);
   dec = spi_registry_dec_new (registry, bus);
 
@@ -343,3 +375,39 @@ main (int argc, char **argv)
   g_main_loop_run (mainloop);
   return 0;
 }
+
+static gboolean
+need_to_quit ()
+{
+  void *gconf = NULL;
+  gconf_client_get_default_t gconf_client_get_default = NULL;
+  gconf_client_get_bool_t gconf_client_get_bool = NULL;
+  GObject *gconf_client;       /* really a GConfClient */
+  gboolean ret;
+
+  g_type_init ();
+
+  gconf = dlopen ("libgconf-2.so", RTLD_LAZY);
+  if (gconf)
+    {
+      gconf_client_get_default = dlsym (gconf, "gconf_client_get_default");
+      gconf_client_get_bool = dlsym (gconf, "gconf_client_get_bool");
+  }
+
+  if (!gconf_client_get_default || !gconf_client_get_bool)
+    {
+      if (gconf)
+        dlclose (gconf);
+      return FALSE;
+    }
+
+  /* If we've been relocated, we will exit if the at-spi-corba gconf key
+ * has been set.  If we have not been relocated, we will only run if the
+ * at-spi-dbus gconf key has been set.
+   */
+  gconf_client = gconf_client_get_default ();
+  ret = gconf_client_get_bool (gconf_client, CORBA_GCONF_KEY, NULL);
+  g_object_unref (gconf_client);
+
+  return ret;
+}