]> git.meshlink.io Git - catta/commitdiff
Rework DBus connection handling: use a private DBusConnection instead of a shared...
authorLennart Poettering <lennart@poettering.net>
Fri, 5 Jan 2007 00:21:19 +0000 (00:21 +0000)
committerLennart Poettering <lennart@poettering.net>
Fri, 5 Jan 2007 00:21:19 +0000 (00:21 +0000)
git-svn-id: file:///home/lennart/svn/public/avahi/trunk@1364 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe

avahi-daemon/Makefile.am
avahi-daemon/dbus-protocol.c

index 973a2b555a273bdd8f4249c6702a8d0b2a031716..02be28838dda8133005cd944b95617ec51a4d492 100644 (file)
@@ -115,7 +115,7 @@ avahi_daemon_SOURCES += \
 avahi_daemon_LDADD += \
        $(DBUS_LIBS)
 
-avahi_daemon_CFLAGS += $(DBUS_CFLAGS)
+avahi_daemon_CFLAGS += $(DBUS_CFLAGS) -DDBUS_SYSTEM_BUS_DEFAULT_ADDRESS=\"$(DBUS_SYSTEM_BUS_DEFAULT_ADDRESS)\"
 
 dbusservice_DATA = avahi-dbus.conf
 
index caa2e19eb7fe27758ad9bfbec39208152379d140..9bfc15113d0fd6d406f39aa08655b93ed6eb0542 100644 (file)
@@ -1051,12 +1051,34 @@ static int dbus_connect(void) {
     assert(!server->bus);
 
     dbus_error_init(&error);
-    
-    if (!(server->bus = dbus_bus_get(DBUS_BUS_SYSTEM, &error))) {
+
+#ifdef HAVE_DBUS_BUS_GET_PRIVATE    
+    if (!(server->bus = dbus_bus_get_private(DBUS_BUS_SYSTEM, &error))) {
         assert(dbus_error_is_set(&error));
-        avahi_log_error("dbus_bus_get(): %s", error.message);
+        avahi_log_error("dbus_bus_get_private(): %s", error.message);
         goto fail;
     }
+#else
+    {
+        const char *a;
+
+        if (!(a = getenv("DBUS_SYSTEM_BUS_ADDRESS")) || !*a)
+            a = DBUS_SYSTEM_BUS_DEFAULT_ADDRESS;
+        
+        if (!(server->bus = dbus_connection_open_private(a, &error))) {
+            assert(dbus_error_is_set(&error));
+            avahi_log_error("dbus_bus_open_private(): %s", error.message);
+            goto fail;
+        }
+
+        if (!dbus_bus_register(server->bus, &error)) {
+            assert(dbus_error_is_set(&error));
+            avahi_log_error("dbus_bus_register(): %s", error.message);
+            goto fail;
+        }
+    }
+#endif
+    
     if (avahi_dbus_connection_glue(server->bus, server->poll_api) < 0) {
         avahi_log_error("avahi_dbus_connection_glue() failed");
         goto fail;
@@ -1106,6 +1128,11 @@ fail:
         dbus_error_free(&error);
 
     if (server->bus) {
+#ifdef HAVE_DBUS_CONNECTION_CLOSE
+        dbus_connection_close(server->bus);
+#else
+        dbus_connection_disconnect(server->bus);
+#endif
         dbus_connection_unref(server->bus);
         server->bus = NULL;
     }
@@ -1122,6 +1149,11 @@ static void dbus_disconnect(void) {
     assert(server->n_clients == 0);
 
     if (server->bus) {
+#ifdef HAVE_DBUS_CONNECTION_CLOSE
+        dbus_connection_close(server->bus);
+#else
+        dbus_connection_disconnect(server->bus);
+#endif
         dbus_connection_unref(server->bus);
         server->bus = NULL;
     }
@@ -1156,6 +1188,12 @@ int dbus_protocol_setup(const AvahiPoll *poll_api, int _disable_user_service_pub
 
 fail:
     if (server->bus) {
+#ifdef HAVE_DBUS_CONNECTION_CLOSE
+        dbus_connection_close(server->bus);
+#else
+        dbus_connection_disconnect(server->bus);
+#endif
+
         dbus_connection_unref(server->bus);
     }