From 56564e11eecf2cf3e02491691c5594d05a0d0410 Mon Sep 17 00:00:00 2001 From: Kevin Wasserman Date: Mon, 25 Nov 2013 18:01:24 -0500 Subject: [PATCH] Do not call dbus_g_bus_get in headless mode on legacy systems Centos exits process when dbus-launch script fails, so don't even try, just call our custom moonshot-dbus-launch. --- Makefile.am | 1 + libmoonshot/libmoonshot-dbus.c | 46 ++++++++++++++++++++++++++---------------- 2 files changed, 30 insertions(+), 17 deletions(-) diff --git a/Makefile.am b/Makefile.am index ffa8110..db1c4f7 100644 --- a/Makefile.am +++ b/Makefile.am @@ -175,6 +175,7 @@ AM_VALAFLAGS += \ --pkg dbus-glib-1 \ --define=IPC_DBUS_GLIB \ --define=IPC_DBUS +AM_CPPFLAGS += -DIPC_DBUS_GLIB else AM_VALAFLAGS += \ --pkg gio-2.0 \ diff --git a/libmoonshot/libmoonshot-dbus.c b/libmoonshot/libmoonshot-dbus.c index df1d46e..84f8975 100644 --- a/libmoonshot/libmoonshot-dbus.c +++ b/libmoonshot/libmoonshot-dbus.c @@ -33,6 +33,7 @@ */ #include +#include #include #include #include @@ -145,25 +146,36 @@ static DBusGProxy *dbus_connect (MoonshotError **error) "Cannot use IPC while setid"); return NULL; } - - 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; + } } - 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; - } dbconnection = dbus_g_connection_get_connection(connection); name_has_owner = dbus_bus_name_has_owner (dbconnection, -- 2.1.4