]> git.meshlink.io Git - catta/commitdiff
client: use Ping() to test whether avahi is around
authorLennart Poettering <lennart@poettering.net>
Mon, 4 Oct 2010 23:14:21 +0000 (01:14 +0200)
committerLennart Poettering <lennart@poettering.net>
Mon, 4 Oct 2010 23:14:21 +0000 (01:14 +0200)
Ping() should work more reliably on systems where dbus activation of
avahi is not available.

http://avahi.org/ticket/319

avahi-client/client.c

index be675ad2bf81305d0786313a59dcad3e16347001..70cc35d9e9290b9ecd1878ddc295fcd60c70a4b8 100644 (file)
@@ -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);