Fixed state of screen-reader wher screen-reader exits abnormally
[platform/upstream/at-spi2-core.git] / bus / at-spi-bus-launcher.c
1 /* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2  * 
3  * at-spi-bus-launcher: Manage the a11y bus as a child process 
4  *
5  * Copyright 2011 Red Hat, Inc.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public
18  * License along with this library; if not, write to the
19  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22
23 #include "config.h"
24
25 #include <unistd.h>
26 #include <string.h>
27 #include <signal.h>
28 #include <sys/wait.h>
29 #include <errno.h>
30 #include <stdio.h>
31
32 #include <gio/gio.h>
33 #ifdef HAVE_X11
34 #include <X11/Xlib.h>
35 #include <X11/Xatom.h>
36 #endif
37
38 #define APP_CONTROL_OPERATION_SCREEN_READ "http://tizen.org/appcontrol/operation/read_screen"
39 #include <appsvc.h>
40 #include <vconf.h>
41 #include <dlog.h>
42 #include <aul.h>
43
44 typedef enum {
45   A11Y_BUS_STATE_IDLE = 0,
46   A11Y_BUS_STATE_READING_ADDRESS,
47   A11Y_BUS_STATE_RUNNING,
48   A11Y_BUS_STATE_ERROR
49 } A11yBusState;
50
51 typedef struct {
52   GMainLoop *loop;
53   gboolean launch_immediately;
54   gboolean a11y_enabled;
55   gboolean screen_reader_enabled;
56   GDBusConnection *session_bus;
57   GSettings *a11y_schema;
58   GSettings *interface_schema;
59
60   gboolean screen_reader_needed;
61   int pid;
62
63   A11yBusState state;
64
65   /* -1 == error, 0 == pending, > 0 == running */
66   int a11y_bus_pid;
67   char *a11y_bus_address;
68   int pipefd[2];
69   char *a11y_launch_error_message;
70 } A11yBusLauncher;
71
72 static A11yBusLauncher *_global_app = NULL;
73
74 static const gchar introspection_xml[] =
75   "<node>"
76   "  <interface name='org.a11y.Bus'>"
77   "    <method name='GetAddress'>"
78   "      <arg type='s' name='address' direction='out'/>"
79   "    </method>"
80   "  </interface>"
81   "<interface name='org.a11y.Status'>"
82   "<property name='IsEnabled' type='b' access='readwrite'/>"
83   "<property name='ScreenReaderEnabled' type='b' access='readwrite'/>"
84   "</interface>"
85   "</node>";
86 static GDBusNodeInfo *introspection_data = NULL;
87
88 static void
89 setup_bus_child (gpointer data)
90 {
91   A11yBusLauncher *app = data;
92   (void) app;
93
94   close (app->pipefd[0]);
95   dup2 (app->pipefd[1], 3);
96   close (app->pipefd[1]);
97
98   /* On Linux, tell the bus process to exit if this process goes away */
99 #ifdef __linux
100 #include <sys/prctl.h>
101   prctl (PR_SET_PDEATHSIG, 15);
102 #endif  
103 }
104
105 /**
106  * unix_read_all_fd_to_string:
107  *
108  * Read all data from a file descriptor to a C string buffer.
109  */
110 static gboolean
111 unix_read_all_fd_to_string (int      fd,
112                             char    *buf,
113                             ssize_t  max_bytes)
114 {
115   ssize_t bytes_read;
116
117   while (max_bytes > 1 && (bytes_read = read (fd, buf, MAX (4096, max_bytes - 1))))
118     {
119       if (bytes_read < 0)
120         return FALSE;
121       buf += bytes_read;
122       max_bytes -= bytes_read;
123     }
124   *buf = '\0';
125   return TRUE;
126 }
127
128 static void
129 on_bus_exited (GPid     pid,
130                gint     status,
131                gpointer data)
132 {
133   A11yBusLauncher *app = data;
134   
135   app->a11y_bus_pid = -1;
136   app->state = A11Y_BUS_STATE_ERROR;
137   if (app->a11y_launch_error_message == NULL)
138     {
139       if (WIFEXITED (status))
140         app->a11y_launch_error_message = g_strdup_printf ("Bus exited with code %d", WEXITSTATUS (status));
141       else if (WIFSIGNALED (status))
142         app->a11y_launch_error_message = g_strdup_printf ("Bus killed by signal %d", WTERMSIG (status));
143       else if (WIFSTOPPED (status))
144         app->a11y_launch_error_message = g_strdup_printf ("Bus stopped by signal %d", WSTOPSIG (status));
145     }
146   g_main_loop_quit (app->loop);
147
148
149 static gboolean
150 ensure_a11y_bus (A11yBusLauncher *app)
151 {
152   GPid pid;
153   char *argv[] = { DBUS_DAEMON, NULL, "--nofork", "--print-address", "3", NULL };
154   char addr_buf[2048];
155   GError *error = NULL;
156
157   if (app->a11y_bus_pid != 0)
158     return FALSE;
159   
160   argv[1] = g_strdup_printf ("--config-file=%s/at-spi2/accessibility.conf", SYSCONFDIR);
161
162   if (pipe (app->pipefd) < 0)
163     g_error ("Failed to create pipe: %s", strerror (errno));
164   
165   if (!g_spawn_async (NULL,
166                       argv,
167                       NULL,
168                       G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD,
169                       setup_bus_child,
170                       app,
171                       &pid,
172                       &error))
173     {
174       app->a11y_bus_pid = -1;
175       app->a11y_launch_error_message = g_strdup (error->message);
176       g_clear_error (&error);
177       goto error;
178     }
179
180   close (app->pipefd[1]);
181   app->pipefd[1] = -1;
182
183   g_child_watch_add (pid, on_bus_exited, app);
184
185   app->state = A11Y_BUS_STATE_READING_ADDRESS;
186   app->a11y_bus_pid = pid;
187   g_debug ("Launched a11y bus, child is %ld", (long) pid);
188   if (!unix_read_all_fd_to_string (app->pipefd[0], addr_buf, sizeof (addr_buf)))
189     {
190       app->a11y_launch_error_message = g_strdup_printf ("Failed to read address: %s", strerror (errno));
191       kill (app->a11y_bus_pid, SIGTERM);
192       goto error;
193     }
194   close (app->pipefd[0]);
195   app->pipefd[0] = -1;
196   app->state = A11Y_BUS_STATE_RUNNING;
197
198   /* Trim the trailing newline */
199   app->a11y_bus_address = g_strchomp (g_strdup (addr_buf));
200   g_debug ("a11y bus address: %s", app->a11y_bus_address);
201
202 #ifdef HAVE_X11
203   {
204     Display *display = XOpenDisplay (NULL);
205     if (display)
206       {
207         Atom bus_address_atom = XInternAtom (display, "AT_SPI_BUS", False);
208         XChangeProperty (display,
209                          XDefaultRootWindow (display),
210                          bus_address_atom,
211                          XA_STRING, 8, PropModeReplace,
212                          (guchar *) app->a11y_bus_address, strlen (app->a11y_bus_address));
213         XFlush (display);
214         XCloseDisplay (display);
215       }
216   }
217 #endif
218
219   return TRUE;
220   
221  error:
222   close (app->pipefd[0]);
223   close (app->pipefd[1]);
224   app->state = A11Y_BUS_STATE_ERROR;
225
226   return FALSE;
227 }
228
229 static void
230 handle_method_call (GDBusConnection       *connection,
231                     const gchar           *sender,
232                     const gchar           *object_path,
233                     const gchar           *interface_name,
234                     const gchar           *method_name,
235                     GVariant              *parameters,
236                     GDBusMethodInvocation *invocation,
237                     gpointer               user_data)
238 {
239   A11yBusLauncher *app = user_data;
240
241   if (g_strcmp0 (method_name, "GetAddress") == 0)
242     {
243       ensure_a11y_bus (app);
244       if (app->a11y_bus_pid > 0)
245         g_dbus_method_invocation_return_value (invocation,
246                                                g_variant_new ("(s)", app->a11y_bus_address));
247       else
248         g_dbus_method_invocation_return_dbus_error (invocation,
249                                                     "org.a11y.Bus.Error",
250                                                     app->a11y_launch_error_message);
251     }
252 }
253
254 static GVariant *
255 handle_get_property  (GDBusConnection       *connection,
256                       const gchar           *sender,
257                       const gchar           *object_path,
258                       const gchar           *interface_name,
259                       const gchar           *property_name,
260                     GError **error,
261                     gpointer               user_data)
262 {
263   A11yBusLauncher *app = user_data;
264
265   if (g_strcmp0 (property_name, "IsEnabled") == 0)
266     return g_variant_new ("b", app->a11y_enabled);
267   else if (g_strcmp0 (property_name, "ScreenReaderEnabled") == 0)
268     return g_variant_new ("b", app->screen_reader_enabled);
269   else
270     return NULL;
271 }
272
273 static void
274 handle_a11y_enabled_change (A11yBusLauncher *app, gboolean enabled,
275                                gboolean notify_gsettings)
276 {
277   GVariantBuilder builder;
278   GVariantBuilder invalidated_builder;
279
280   if (enabled == app->a11y_enabled)
281     return;
282
283   app->a11y_enabled = enabled;
284
285   if (notify_gsettings && app->interface_schema)
286     {
287       g_settings_set_boolean (app->interface_schema, "toolkit-accessibility",
288                               enabled);
289       g_settings_sync ();
290     }
291
292   g_variant_builder_init (&builder, G_VARIANT_TYPE_ARRAY);
293   g_variant_builder_init (&invalidated_builder, G_VARIANT_TYPE ("as"));
294   g_variant_builder_add (&builder, "{sv}", "IsEnabled",
295                          g_variant_new_boolean (enabled));
296
297   g_dbus_connection_emit_signal (app->session_bus, NULL, "/org/a11y/bus",
298                                  "org.freedesktop.DBus.Properties",
299                                  "PropertiesChanged",
300                                  g_variant_new ("(sa{sv}as)", "org.a11y.Status",
301                                                 &builder,
302                                                 &invalidated_builder),
303                                  NULL);
304 }
305
306 static void
307 handle_screen_reader_enabled_change (A11yBusLauncher *app, gboolean enabled,
308                                gboolean notify_gsettings)
309 {
310   GVariantBuilder builder;
311   GVariantBuilder invalidated_builder;
312
313   if (enabled == app->screen_reader_enabled)
314     return;
315
316   /* If the screen reader is being enabled, we should enable accessibility
317    * if it isn't enabled already */
318   if (enabled)
319     handle_a11y_enabled_change (app, enabled, notify_gsettings);
320
321   app->screen_reader_enabled = enabled;
322
323   if (notify_gsettings && app->a11y_schema)
324     {
325       g_settings_set_boolean (app->a11y_schema, "screen-reader-enabled",
326                               enabled);
327       g_settings_sync ();
328     }
329
330   g_variant_builder_init (&builder, G_VARIANT_TYPE_ARRAY);
331   g_variant_builder_init (&invalidated_builder, G_VARIANT_TYPE ("as"));
332   g_variant_builder_add (&builder, "{sv}", "ScreenReaderEnabled",
333                          g_variant_new_boolean (enabled));
334
335   g_dbus_connection_emit_signal (app->session_bus, NULL, "/org/a11y/bus",
336                                  "org.freedesktop.DBus.Properties",
337                                  "PropertiesChanged",
338                                  g_variant_new ("(sa{sv}as)", "org.a11y.Status",
339                                                 &builder,
340                                                 &invalidated_builder),
341                                  NULL);
342 }
343
344 static gboolean
345 handle_set_property  (GDBusConnection       *connection,
346                       const gchar           *sender,
347                       const gchar           *object_path,
348                       const gchar           *interface_name,
349                       const gchar           *property_name,
350                       GVariant *value,
351                     GError **error,
352                     gpointer               user_data)
353 {
354   A11yBusLauncher *app = user_data;
355   const gchar *type = g_variant_get_type_string (value);
356   gboolean enabled;
357   
358   if (g_strcmp0 (type, "b") != 0)
359     {
360       g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS,
361                        "org.a11y.Status.%s expects a boolean but got %s", property_name, type);
362       return FALSE;
363     }
364
365   enabled = g_variant_get_boolean (value);
366
367   if (g_strcmp0 (property_name, "IsEnabled") == 0)
368     {
369       handle_a11y_enabled_change (app, enabled, TRUE);
370       return TRUE;
371     }
372   else if (g_strcmp0 (property_name, "ScreenReaderEnabled") == 0)
373     {
374       handle_screen_reader_enabled_change (app, enabled, TRUE);
375       return TRUE;
376     }
377   else
378     {
379       g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS,
380                        "Unknown property '%s'", property_name);
381       return FALSE;
382     }
383 }
384
385 static const GDBusInterfaceVTable bus_vtable =
386 {
387   handle_method_call,
388   NULL, /* handle_get_property, */
389   NULL  /* handle_set_property */
390 };
391
392 static const GDBusInterfaceVTable status_vtable =
393 {
394   NULL, /* handle_method_call */
395   handle_get_property,
396   handle_set_property
397 };
398
399 static void
400 on_bus_acquired (GDBusConnection *connection,
401                  const gchar     *name,
402                  gpointer         user_data)
403 {
404   A11yBusLauncher *app = user_data;
405   GError *error;
406   guint registration_id;
407   
408   if (connection == NULL)
409     {
410       g_main_loop_quit (app->loop);
411       return;
412     }
413   app->session_bus = connection;
414
415   if (app->launch_immediately)
416     {
417       ensure_a11y_bus (app);
418       if (app->state == A11Y_BUS_STATE_ERROR)
419         {
420           g_main_loop_quit (app->loop);
421           return;
422         }
423     }
424
425   error = NULL;
426   registration_id = g_dbus_connection_register_object (connection,
427                                                        "/org/a11y/bus",
428                                                        introspection_data->interfaces[0],
429                                                        &bus_vtable,
430                                                        _global_app,
431                                                        NULL,
432                                                        &error);
433   if (registration_id == 0)
434     {
435       g_error ("%s", error->message);
436       g_clear_error (&error);
437     }
438
439   g_dbus_connection_register_object (connection,
440                                      "/org/a11y/bus",
441                                      introspection_data->interfaces[1],
442                                      &status_vtable,
443                                      _global_app,
444                                      NULL,
445                                      NULL);
446 }
447
448 static void
449 on_name_lost (GDBusConnection *connection,
450               const gchar     *name,
451               gpointer         user_data)
452 {
453   A11yBusLauncher *app = user_data;
454   if (app->session_bus == NULL
455       && connection == NULL
456       && app->a11y_launch_error_message == NULL)
457     app->a11y_launch_error_message = g_strdup ("Failed to connect to session bus");
458   g_main_loop_quit (app->loop);
459 }
460
461 static void
462 on_name_acquired (GDBusConnection *connection,
463                   const gchar     *name,
464                   gpointer         user_data)
465 {
466   A11yBusLauncher *app = user_data;
467   (void) app;
468 }
469
470 static int sigterm_pipefd[2];
471
472 static void
473 sigterm_handler (int signum)
474 {
475   write (sigterm_pipefd[1], "X", 1);
476 }
477
478 static gboolean
479 on_sigterm_pipe (GIOChannel  *channel,
480                  GIOCondition condition,
481                  gpointer     data)
482 {
483   A11yBusLauncher *app = data;
484   
485   g_main_loop_quit (app->loop);
486
487   return FALSE;
488 }
489
490 static void
491 init_sigterm_handling (A11yBusLauncher *app)
492 {
493   GIOChannel *sigterm_channel;
494
495   if (pipe (sigterm_pipefd) < 0)
496     g_error ("Failed to create pipe: %s", strerror (errno));
497   signal (SIGTERM, sigterm_handler);
498
499   sigterm_channel = g_io_channel_unix_new (sigterm_pipefd[0]);
500   g_io_add_watch (sigterm_channel,
501                   G_IO_IN | G_IO_ERR | G_IO_HUP,
502                   on_sigterm_pipe,
503                   app);
504 }
505
506 static gboolean
507 already_running ()
508 {
509 #ifdef HAVE_X11
510   Atom AT_SPI_BUS;
511   Atom actual_type;
512   Display *bridge_display;
513   int actual_format;
514   unsigned char *data = NULL;
515   unsigned long nitems;
516   unsigned long leftover;
517   gboolean result = FALSE;
518
519   bridge_display = XOpenDisplay (NULL);
520   if (!bridge_display)
521               return FALSE;
522       
523   AT_SPI_BUS = XInternAtom (bridge_display, "AT_SPI_BUS", False);
524   XGetWindowProperty (bridge_display,
525                       XDefaultRootWindow (bridge_display),
526                       AT_SPI_BUS, 0L,
527                       (long) BUFSIZ, False,
528                       (Atom) 31, &actual_type, &actual_format,
529                       &nitems, &leftover, &data);
530
531   if (data)
532   {
533     GDBusConnection *bus;
534     bus = g_dbus_connection_new_for_address_sync ((const gchar *)data, 0,
535                                                   NULL, NULL, NULL);
536     if (bus != NULL)
537       {
538         result = TRUE;
539         g_object_unref (bus);
540       }
541   }
542
543   XCloseDisplay (bridge_display);
544   return result;
545 #else
546   return FALSE;
547 #endif
548 }
549
550 static GSettings *
551 get_schema (const gchar *name)
552 {
553   const char * const *schemas = NULL;
554   gint i;
555
556   schemas = g_settings_list_schemas ();
557   for (i = 0; schemas[i]; i++)
558   {
559     if (!strcmp (schemas[i], name))
560       return g_settings_new (schemas[i]);
561   }
562
563   return NULL;
564 }
565
566 static void
567 gsettings_key_changed (GSettings *gsettings, const gchar *key, void *user_data)
568 {
569   gboolean new_val = g_settings_get_boolean (gsettings, key);
570   A11yBusLauncher *app = user_data;
571
572   if (!strcmp (key, "toolkit-accessibility"))
573     handle_a11y_enabled_change (_global_app, new_val, FALSE);
574   else if (!strcmp (key, "screen-reader-enabled"))
575     handle_screen_reader_enabled_change (_global_app, new_val, FALSE);
576 }
577
578 static gboolean
579 _launch_screen_reader(A11yBusLauncher *bl)
580 {
581    bundle *kb = NULL;
582    gboolean ret = FALSE;
583
584    kb = bundle_create();
585    if (kb == NULL)
586      return FALSE;
587
588    bl->pid = aul_launch_app("org.tizen.screen-reader", kb);
589    if (bl->pid >= 0) {
590        ret = TRUE;
591    }
592
593    bundle_free(kb);
594    return ret;
595 }
596
597 static gboolean
598 _terminate_screen_reader(A11yBusLauncher *bl)
599 {
600    int ret;
601    if (bl->pid <= 0)
602      return FALSE;
603
604
605    int status = aul_app_get_status_bypid(bl->pid);
606
607    if (status < 0)
608      {
609         LOGD("App with pid %d already terminated", bl->pid);
610         bl->pid = 0;
611         return TRUE;
612      }
613
614    LOGD("terminate process with pid %d", bl->pid);
615    if (!aul_terminate_pid(bl->pid))
616      {
617         bl->pid = 0;
618         return TRUE;
619      }
620
621    LOGD("Unable to terminate process using aul api. Sending SIGTERM signal");
622    ret = kill(bl->pid, SIGTERM);
623    if (!ret)
624      {
625         bl->pid = 0;
626         return TRUE;
627      }
628
629    LOGD("Unable to terminate process: %d with api or signal.", bl->pid);
630    return FALSE;
631 }
632
633 void screen_reader_cb(keynode_t *node, void *user_data)
634 {
635    A11yBusLauncher *bl = user_data;
636    int ret;
637
638    ret = vconf_keynode_get_bool(node);
639    if (ret < 0)
640      return;
641
642    bl->screen_reader_needed = ret;
643
644    if (!bl->screen_reader_needed && (bl->pid > 0))
645      _terminate_screen_reader(bl);
646    else if (bl->screen_reader_needed && (bl->pid <= 0))
647      _launch_screen_reader(bl);
648 }
649
650 int
651 main (int    argc,
652       char **argv)
653 {
654   GError *error = NULL;
655   GMainLoop *loop;
656   GDBusConnection *session_bus;
657   int name_owner_id;
658   gboolean a11y_set = FALSE;
659   gboolean screen_reader_set = FALSE;
660   gint i;
661
662   if (already_running ())
663     return 0;
664
665   _global_app = g_slice_new0 (A11yBusLauncher);
666   _global_app->loop = g_main_loop_new (NULL, FALSE);
667
668   for (i = 1; i < argc; i++)
669     {
670       if (!strcmp (argv[i], "--launch-immediately"))
671         _global_app->launch_immediately = TRUE;
672       else if (sscanf (argv[i], "--a11y=%d", &_global_app->a11y_enabled) == 2)
673         a11y_set = TRUE;
674       else if (sscanf (argv[i], "--screen-reader=%d",
675                        &_global_app->screen_reader_enabled) == 2)
676         screen_reader_set = TRUE;
677     else
678       g_error ("usage: %s [--launch-immediately] [--a11y=0|1] [--screen-reader=0|1]", argv[0]);
679     }
680
681   _global_app->interface_schema = get_schema ("org.gnome.desktop.interface");
682   _global_app->a11y_schema = get_schema ("org.gnome.desktop.a11y.applications");
683
684   if (!a11y_set)
685     {
686       _global_app->a11y_enabled = _global_app->interface_schema
687                                   ? g_settings_get_boolean (_global_app->interface_schema, "toolkit-accessibility")
688                                   : _global_app->launch_immediately;
689     }
690
691   if (!screen_reader_set)
692     {
693       _global_app->screen_reader_enabled = _global_app->a11y_schema
694                                   ? g_settings_get_boolean (_global_app->a11y_schema, "screen-reader-enabled")
695                                   : FALSE;
696     }
697
698   if (_global_app->interface_schema)
699     g_signal_connect (_global_app->interface_schema,
700                       "changed::toolkit-accessibility",
701                       G_CALLBACK (gsettings_key_changed), _global_app);
702
703   if (_global_app->a11y_schema)
704     g_signal_connect (_global_app->a11y_schema,
705                       "changed::screen-reader-enabled",
706                       G_CALLBACK (gsettings_key_changed), _global_app);
707
708   init_sigterm_handling (_global_app);
709
710   introspection_data = g_dbus_node_info_new_for_xml (introspection_xml, NULL);
711   g_assert (introspection_data != NULL);
712
713   name_owner_id = g_bus_own_name (G_BUS_TYPE_SESSION,
714                                   "org.a11y.Bus",
715                                   G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT,
716                                   on_bus_acquired,
717                                   on_name_acquired,
718                                   on_name_lost,
719                                   _global_app,
720                                   NULL);
721
722   int ret = vconf_get_bool(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, &_global_app->screen_reader_needed);
723   if (ret != 0)
724     {
725       LOGD("Could not read VCONFKEY_SETAPPL_ACCESSIBILITY_TTS key value.\n");
726       return FALSE;
727     }
728   ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, screen_reader_cb, _global_app);
729   if(ret != 0)
730     {
731       LOGD("Could not add information level callback\n");
732       return FALSE;
733     }
734   if (_global_app->screen_reader_needed)
735     _launch_screen_reader(_global_app);
736
737   g_main_loop_run (_global_app->loop);
738
739   if (_global_app->a11y_bus_pid > 0)
740     kill (_global_app->a11y_bus_pid, SIGTERM);
741
742   /* Clear the X property if our bus is gone; in the case where e.g. 
743    * GDM is launching a login on an X server it was using before,
744    * we don't want early login processes to pick up the stale address.
745    */
746 #ifdef HAVE_X11
747   {
748     Display *display = XOpenDisplay (NULL);
749     if (display)
750       {
751         Atom bus_address_atom = XInternAtom (display, "AT_SPI_BUS", False);
752         XDeleteProperty (display,
753                          XDefaultRootWindow (display),
754                          bus_address_atom);
755
756         XFlush (display);
757         XCloseDisplay (display);
758       }
759   }
760 #endif
761
762   if (_global_app->a11y_launch_error_message)
763     {
764       g_printerr ("Failed to launch bus: %s", _global_app->a11y_launch_error_message);
765       return 1;
766     }
767   return 0;
768 }