From bb421d3a4e8e9bbf99c340f5559e6fd76dac5196 Mon Sep 17 00:00:00 2001 From: Trent Lloyd Date: Tue, 23 Aug 2005 21:50:39 +0000 Subject: * avahi-client/ - Create a new function avahi_dbus_bus_get which acts like dbus_bus_get but instead gets a private connection, this solves the bug where you can't have more than one AvahiClient at once because each successive AvahiClient stepped on the DBusWatch handling of the previous due to libdbus liking to recycle its connections. Introduced a new configure option --with-dbus-system-address= if you set this, you likely want it set to unix:path=/some/socket/here The default is /var/run/dbus/system_socket_address, because this path is hard coded into D-BUS itself, and the DBUS_SYSTEM_BUS_ADDRESS environment variable is now supported to change this at runtime which is inline with libdbus. git-svn-id: file:///home/lennart/svn/public/avahi/trunk@432 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe --- avahi-client/Makefile.am | 2 +- avahi-client/client.c | 39 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 2 deletions(-) (limited to 'avahi-client') diff --git a/avahi-client/Makefile.am b/avahi-client/Makefile.am index cdc4442..75e18a2 100644 --- a/avahi-client/Makefile.am +++ b/avahi-client/Makefile.am @@ -39,7 +39,7 @@ libavahi_client_la_SOURCES = \ browser.c \ resolver.c -libavahi_client_la_CFLAGS = $(AM_CFLAGS) $(DBUS_CFLAGS) +libavahi_client_la_CFLAGS = $(AM_CFLAGS) $(DBUS_CFLAGS) -DDBUS_SYSTEM_BUS_DEFAULT_ADDRESS=\"$(DBUS_SYSTEM_BUS_DEFAULT_ADDRESS)\" libavahi_client_la_LIBADD = $(AM_LDADD) $(DBUS_LIBS) ../avahi-common/libavahi-common.la ../avahi-common/libdbus-common-pic.la libavahi_client_la_LDFLAGS = $(AM_LDFLAGS) -export-dynamic -version-info 1:0:1 diff --git a/avahi-client/client.c b/avahi-client/client.c index bb623c0..27f7462 100644 --- a/avahi-client/client.c +++ b/avahi-client/client.c @@ -232,6 +232,43 @@ fail: return e; } +/* This function acts like dbus_bus_get but creates a private + * connection instead */ +static DBusConnection* +avahi_dbus_bus_get (DBusBusType type, DBusError *error) +{ + DBusConnection *conn; + char *env_addr; + + env_addr = getenv ("DBUS_SYSTEM_BUS_ADDRESS"); + + if (env_addr == NULL || (strcmp (env_addr, "") == 0)) + { + env_addr = DBUS_SYSTEM_BUS_DEFAULT_ADDRESS; + } + + conn = dbus_connection_open_private (env_addr, error); + + if (!conn) + { + printf ("Failed to open private connection: %s\n", error->message); + return NULL; + } + + dbus_connection_set_exit_on_disconnect (conn, TRUE); + + if (!dbus_bus_register (conn, error)) + { + printf ("Failed to register connection\n"); + dbus_connection_close (conn); + dbus_connection_unref (conn); + + return NULL; + } + + return conn; +} + AvahiClient *avahi_client_new(const AvahiPoll *poll_api, AvahiClientCallback callback, void *userdata, int *ret_error) { AvahiClient *client = NULL; DBusError error; @@ -261,7 +298,7 @@ AvahiClient *avahi_client_new(const AvahiPoll *poll_api, AvahiClientCallback cal AVAHI_LLIST_HEAD_INIT(AvahiServiceTypeBrowser, client->service_type_browsers); AVAHI_LLIST_HEAD_INIT(AvahiServiceResolver, client->service_resolvers); - if (!(client->bus = dbus_bus_get(DBUS_BUS_SYSTEM, &error)) || + if (!(client->bus = avahi_dbus_bus_get(DBUS_BUS_SYSTEM, &error)) || dbus_error_is_set (&error)) goto fail; -- cgit