-
- connection = dbus_g_bus_get (DBUS_BUS_SESSION, &g_error);
-
- if (g_error_matches(g_error, DBUS_GERROR, DBUS_GERROR_NOT_SUPPORTED)) {
- /*Generally this means autolaunch failed because probably DISPLAY is unset*/
- connection = dbus_launch_moonshot();
- if (connection != NULL) {
- g_error_free(g_error);
- g_error = NULL;
- }
+#ifdef IPC_DBUS_GLIB
+ if (getenv("DISPLAY")==NULL) {
+ connection = dbus_launch_moonshot();
+ if (connection == NULL) {
+ *error = moonshot_error_new (MOONSHOT_ERROR_IPC_ERROR,
+ "Headless dbus launch failed");
+ return NULL;
+ }
+ } else
+#endif
+ {
+ connection = dbus_g_bus_get (DBUS_BUS_SESSION, &g_error);
+
+ if (g_error_matches(g_error, DBUS_GERROR, DBUS_GERROR_NOT_SUPPORTED)) {
+ /*Generally this means autolaunch failed because probably DISPLAY is unset*/
+ connection = dbus_launch_moonshot();
+ if (connection != NULL) {
+ g_error_free(g_error);
+ g_error = NULL;
+ }
+ }
+ if (g_error != NULL) {
+ *error = moonshot_error_new (MOONSHOT_ERROR_IPC_ERROR,
+ "DBus error: %s",
+ g_error->message);
+ g_error_free (g_error);
+ return NULL;
+ }