Do not call dbus_g_bus_get in headless mode on legacy systems
authorKevin Wasserman <kevin.wasserman@painless-security.com>
Mon, 25 Nov 2013 23:01:24 +0000 (18:01 -0500)
committerKevin Wasserman <kevin.wasserman@painless-security.com>
Mon, 25 Nov 2013 23:01:24 +0000 (18:01 -0500)
Centos exits process when dbus-launch script fails, so don't even try,
just call our custom moonshot-dbus-launch.

Makefile.am
libmoonshot/libmoonshot-dbus.c

index ffa8110..db1c4f7 100644 (file)
@@ -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 \
index df1d46e..84f8975 100644 (file)
@@ -33,6 +33,7 @@
  */
 
 #include <assert.h>
+#include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
 #include <dbus/dbus-glib.h>
@@ -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,