From 55c732acd013b6ac979b6e1f5432a301481879ca Mon Sep 17 00:00:00 2001
From: Sjoerd Simons <sjoerd.simons@collabora.co.uk>
Date: Sun, 15 Aug 2010 22:56:49 +0100
Subject: [PATCH] Check if the deamon isn't already running
---
avahi-client/client.c | 29 +++++++++++++++++++++++++----
1 files changed, 25 insertions(+), 4 deletions(-)
diff --git a/avahi-client/client.c b/avahi-client/client.c
index be675ad..c7ece4a 100644
|
a
|
b
|
|
| 478 | 478 | AvahiClient *avahi_client_new(const AvahiPoll *poll_api, AvahiClientFlags flags, AvahiClientCallback callback, void *userdata, int *ret_error) { |
| 479 | 479 | AvahiClient *client = NULL; |
| 480 | 480 | DBusError error; |
| | 481 | int daemon_running = 0; |
| 481 | 482 | |
| 482 | 483 | avahi_init_i18n(); |
| 483 | 484 | |
| … |
… |
|
| 560 | 561 | if (dbus_error_is_set(&error)) |
| 561 | 562 | goto fail; |
| 562 | 563 | |
| 563 | | if (!dbus_bus_start_service_by_name(client->bus, AVAHI_DBUS_NAME, 0, NULL, &error)) { |
| 564 | 564 | |
| 565 | | /* We free the error so its not set, that way the fail target |
| 566 | | * will return the NO_DAEMON error rather than a DBUS error */ |
| | 565 | /* Check if the process already exists on the bus, otherwise try to start |
| | 566 | * it. */ |
| | 567 | if (!dbus_bus_name_has_owner (client->bus, AVAHI_DBUS_NAME, &error)) { |
| | 568 | dbus_error_free(&error); |
| | 569 | daemon_running = 0; |
| | 570 | } else { |
| | 571 | daemon_running = 1; |
| | 572 | } |
| | 573 | |
| | 574 | if (!daemon_running && |
| | 575 | !dbus_bus_start_service_by_name(client->bus, |
| | 576 | AVAHI_DBUS_NAME, 0, NULL, &error)) { |
| 567 | 577 | dbus_error_free(&error); |
| | 578 | } else { |
| | 579 | daemon_running = 1; |
| | 580 | } |
| 568 | 581 | |
| | 582 | /* Re-check something else didn't start the daemon */ |
| | 583 | if (!daemon_running && |
| | 584 | !dbus_bus_name_has_owner (client->bus, AVAHI_DBUS_NAME, &error)) { |
| | 585 | dbus_error_free(&error); |
| | 586 | } else { |
| | 587 | daemon_running = 1; |
| | 588 | } |
| | 589 | |
| | 590 | if (!daemon_running) { |
| 569 | 591 | if (!(flags & AVAHI_CLIENT_NO_FAIL)) { |
| 570 | 592 | |
| 571 | 593 | if (ret_error) |
| … |
… |
|
| 577 | 599 | /* The user doesn't want this call to fail if the daemon is not |
| 578 | 600 | * available, so let's return succesfully */ |
| 579 | 601 | client_set_state(client, AVAHI_CLIENT_CONNECTING); |
| 580 | | |
| 581 | 602 | } else { |
| 582 | 603 | |
| 583 | 604 | if (init_server(client, ret_error) < 0) |