test-autolaunch.c 1.25 KB
Newer Older
1 2
#include "config.h"

Colin Walters's avatar
Colin Walters committed
3 4 5 6 7 8 9 10
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif

#include <dbus/dbus.h>
11
#include "dbus/dbus-sysdeps.h"
Colin Walters's avatar
Colin Walters committed
12 13 14 15 16 17 18

int
main (int argc, char *argv[])
{
  DBusConnection *conn = NULL;
  DBusError error;

19
  dbus_setenv ("DBUS_SESSION_BUS_ADDRESS", NULL);
Colin Walters's avatar
Colin Walters committed
20 21 22 23

  dbus_error_init (&error);

  conn = dbus_bus_get (DBUS_BUS_SESSION, &error);
24

25
#ifdef DBUS_ENABLE_X11_AUTOLAUNCH
26 27
  /* If X11 autolaunch was enabled, we expect dbus-launch to have worked. */
  if (_dbus_getenv ("DISPLAY") != NULL && dbus_error_is_set (&error))
Colin Walters's avatar
Colin Walters committed
28 29 30 31 32 33
    {
      fprintf (stderr, "*** Failed to autolaunch session bus: %s\n",
               error.message);
      dbus_error_free (&error);
      return 1;
    }
34 35
#endif

36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
  /* We don't necessarily expect it to *work* without X (although it might -
   * for instance on Mac OS it might have used launchd). Just check that the
   * results are consistent. */

  if (dbus_error_is_set (&error) && conn != NULL)
    {
      fprintf (stderr, "*** Autolaunched session bus, but an error was set!\n");
      return 1;
    }

  if (!dbus_error_is_set (&error) && conn == NULL)
    {
      fprintf (stderr, "*** Failed to autolaunch session bus but no error was set\n");
      return 1;
    }
Colin Walters's avatar
Colin Walters committed
51 52 53

  return 0;
}