summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBryan Quigley <gquigs@gmail.com>2014-08-04 12:26:00 -0400
committerMichael Stahl <mstahl@redhat.com>2014-08-08 20:21:02 +0000
commitd2eec11f0a6f27e13a4a834942f8acf20ae62cec (patch)
tree32f3cdb0559919a803f181b1619093e7d5f674f4
parent22731ba9e15978ab1d1ed98a29d88431cf674257 (diff)
fdo#81552 Fail nicely if avahi doesn't let libreoffice publish items
Change-Id: Ie264a032a71bda336158e18bd2b14c569f23f42d Reviewed-on: https://gerrit.libreoffice.org/10735 Reviewed-by: Michael Stahl <mstahl@redhat.com> Tested-by: Michael Stahl <mstahl@redhat.com> (cherry picked from commit 3c57701cf0a169bd8d1893d1b2271d48b8072147) Reviewed-on: https://gerrit.libreoffice.org/10816
-rw-r--r--sd/source/ui/remotecontrol/AvahiNetworkService.cxx26
1 files changed, 17 insertions, 9 deletions
diff --git a/sd/source/ui/remotecontrol/AvahiNetworkService.cxx b/sd/source/ui/remotecontrol/AvahiNetworkService.cxx
index d4d92cd63fe4..ad2bfef61aff 100644
--- a/sd/source/ui/remotecontrol/AvahiNetworkService.cxx
+++ b/sd/source/ui/remotecontrol/AvahiNetworkService.cxx
@@ -35,7 +35,7 @@ static AvahiThreadedPoll *threaded_poll = NULL;
static AvahiEntryGroup *group = NULL;
static AvahiNetworkService *avahiService = NULL;
-static void create_services(AvahiClient *c);
+static bool create_services(AvahiClient *c);
static void entry_group_callback(AvahiEntryGroup *g, AvahiEntryGroupState state, AVAHI_GCC_UNUSED void *userdata) {
assert(g == group || group == NULL);
@@ -78,16 +78,19 @@ static void entry_group_callback(AvahiEntryGroup *g, AvahiEntryGroupState state,
}
}
-static void create_services(AvahiClient *c) {
+static bool create_services(AvahiClient *c) {
assert(c);
/* If this is the first time we're called, let's create a new
* entry group if necessary */
+ if(!client)
+ return false;
if (!group)
if (!(group = avahi_entry_group_new(c, entry_group_callback, NULL))) {
SAL_WARN("sdremote.wifi", "avahi_entry_group_new() failed: " << avahi_strerror(avahi_client_errno(c)));
avahiService->clear();
+ return false;
}
/* If the group is empty (either because it was just created, or
@@ -113,22 +116,23 @@ static void create_services(AvahiClient *c) {
avahi_entry_group_reset(group);
- create_services(c);
- return;
+ return create_services(c);
}
SAL_WARN("sdremote.wifi", "Failed to add _impressremote._tcp service: " << avahi_strerror(ret));
avahiService->clear();
+ return false;
}
/* Tell the server to register the service */
if ((ret = avahi_entry_group_commit(group)) < 0) {
SAL_WARN("sdremote.wifi", "Failed to commit entry group: " << avahi_strerror(ret));
avahiService->clear();
+ return false;
}
}
- return;
+ return true; //Services we're already created
}
static void client_callback(AvahiClient *c, AvahiClientState state, AVAHI_GCC_UNUSED void * userdata) {
@@ -174,7 +178,8 @@ void AvahiNetworkService::setup() {
return;
}
- create_services(client);
+ if(!create_services(client))
+ return;
/* Finally, start the event loop thread */
if (avahi_threaded_poll_start(threaded_poll) < 0) {
@@ -185,7 +190,10 @@ void AvahiNetworkService::setup() {
void AvahiNetworkService::clear() {
/* Call this when the app shuts down */
- avahi_threaded_poll_stop(threaded_poll);
- avahi_client_free(client);
- avahi_threaded_poll_free(threaded_poll);
+ if(threaded_poll)
+ avahi_threaded_poll_stop(threaded_poll);
+ if(client)
+ avahi_client_free(client);
+ if(threaded_poll)
+ avahi_threaded_poll_free(threaded_poll);
}