diff options
author | Lennart Poettering <lennart@poettering.net> | 2010-10-05 01:14:21 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2010-10-05 01:14:21 +0200 |
commit | 9a4db66ee760635ddc7e734ec182143cf6f729d3 (patch) | |
tree | b78bb5fed4a4a4cdbfbbd7dd9b7f58b2c823d436 | |
parent | 4da9969a61b52d388b48cb567be75ac7b1dcfe5e (diff) |
client: use Ping() to test whether avahi is around
Ping() should work more reliably on systems where dbus activation of
avahi is not available.
http://avahi.org/ticket/319
-rw-r--r-- | avahi-client/client.c | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/avahi-client/client.c b/avahi-client/client.c index be675ad..70cc35d 100644 --- a/avahi-client/client.c +++ b/avahi-client/client.c @@ -478,6 +478,7 @@ static DBusConnection* avahi_dbus_bus_get(DBusError *error) { AvahiClient *avahi_client_new(const AvahiPoll *poll_api, AvahiClientFlags flags, AvahiClientCallback callback, void *userdata, int *ret_error) { AvahiClient *client = NULL; DBusError error; + DBusMessage *message = NULL, *reply = NULL; avahi_init_i18n(); @@ -551,7 +552,7 @@ AvahiClient *avahi_client_new(const AvahiPoll *poll_api, AvahiClientFlags flags, if (dbus_error_is_set(&error)) goto fail; - dbus_bus_add_match ( + dbus_bus_add_match( client->bus, "type='signal', " "interface='" DBUS_INTERFACE_LOCAL "'", @@ -560,8 +561,12 @@ AvahiClient *avahi_client_new(const AvahiPoll *poll_api, AvahiClientFlags flags, if (dbus_error_is_set(&error)) goto fail; - if (!dbus_bus_start_service_by_name(client->bus, AVAHI_DBUS_NAME, 0, NULL, &error)) { + if (!(message = dbus_message_new_method_call(AVAHI_DBUS_NAME, AVAHI_DBUS_PATH_SERVER, "org.freedesktop.DBus.Peer", "Ping"))) + goto fail; + reply = dbus_connection_send_with_reply_and_block (client->bus, message, -1, &error); + + if (!reply || dbus_error_is_set (&error)) { /* We free the error so its not set, that way the fail target * will return the NO_DAEMON error rather than a DBUS error */ dbus_error_free(&error); @@ -584,10 +589,20 @@ AvahiClient *avahi_client_new(const AvahiPoll *poll_api, AvahiClientFlags flags, goto fail; } + dbus_message_unref(message); + + if (reply) + dbus_message_unref(reply); + return client; fail: + if (message) + dbus_message_unref(message); + if (reply) + dbus_message_unref(reply); + if (client) avahi_client_free(client); |