• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #ifdef HAVE_UNISTD_H
5 #include <unistd.h>
6 #endif
7 
8 #include <dbus/dbus.h>
9 #include "dbus/dbus-sysdeps.h"
10 
11 int
main(int argc,char * argv[])12 main (int argc, char *argv[])
13 {
14   DBusConnection *conn = NULL;
15   DBusError error;
16 
17   _dbus_setenv ("DBUS_SESSION_BUS_ADDRESS", NULL);
18 
19   dbus_error_init (&error);
20 
21   conn = dbus_bus_get (DBUS_BUS_SESSION, &error);
22 
23 #ifdef DBUS_ENABLE_X11_AUTOLAUNCH
24   if (dbus_error_is_set (&error))
25     {
26       fprintf (stderr, "*** Failed to autolaunch session bus: %s\n",
27                error.message);
28       dbus_error_free (&error);
29       return 1;
30     }
31 #else
32   /* We don't necessarily expect it to *work* without X (although it might -
33    * for instance on Mac OS it might have used launchd). Just check that the
34    * results are consistent. */
35 
36   if (dbus_error_is_set (&error) && conn != NULL)
37     {
38       fprintf (stderr, "*** Autolaunched session bus, but an error was set!\n");
39       return 1;
40     }
41 #endif
42 
43   if (!dbus_error_is_set (&error) && conn == NULL)
44     {
45       fprintf (stderr, "*** Failed to autolaunch session bus but no error was set\n");
46       return 1;
47     }
48 
49   return 0;
50 }
51