Skip to content

Commit

Permalink
Correct mishandling of avahi poll-thread error conditions. This was c…
Browse files Browse the repository at this point in the history
…ausing Shairport Sync to crash e.g. when the network disappeared
  • Loading branch information
mikebrady committed Mar 17, 2016
1 parent cdd04c1 commit 7b3694d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 31 deletions.
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Process this file with autoconf to produce a configure script.

AC_PREREQ([2.50])
AC_INIT([shairport-sync], [2.9.3], [[email protected]])
AC_INIT([shairport-sync], [2.9.4], [[email protected]])
AM_INIT_AUTOMAKE
AC_CONFIG_SRCDIR([shairport.c])
AC_CONFIG_HEADERS([config.h])
Expand Down
64 changes: 34 additions & 30 deletions mdns_avahi.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,44 +45,47 @@ static int port = 0;
static void egroup_callback(AvahiEntryGroup *g, AvahiEntryGroupState state,
AVAHI_GCC_UNUSED void *userdata) {
if (state == AVAHI_ENTRY_GROUP_COLLISION)
die("service name already exists on network!");
warn("Service name already exists on network!");
if (state == AVAHI_ENTRY_GROUP_FAILURE)
die("avahi entry group failure!");
warn("Avahi entry group failure!");
}

static void register_service(AvahiClient *c) {
debug(1, "avahi: register_service.");
if (!group)
group = avahi_entry_group_new(c, egroup_callback, NULL);
if (!group)
die("avahi_entry_group_new failed");

if (!avahi_entry_group_is_empty(group))
return;

int ret;
#ifdef CONFIG_METADATA
if (config.metadata_enabled) {
debug(1, "Avahi with metadata");
ret = avahi_entry_group_add_service(group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0, name,
"_raop._tcp", NULL, NULL, port, MDNS_RECORD_WITH_METADATA,
NULL);
} else {
#endif
debug(1, "Avahi without metadata");
ret = avahi_entry_group_add_service(group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0, name,
"_raop._tcp", NULL, NULL, port,
MDNS_RECORD_WITHOUT_METADATA, NULL);
#ifdef CONFIG_METADATA
warn("avahi_entry_group_new failed");
else {

if (!avahi_entry_group_is_empty(group))
return;

int ret;
#ifdef CONFIG_METADATA
if (config.metadata_enabled) {
debug(1, "Avahi with metadata");
ret = avahi_entry_group_add_service(group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0, name,
"_raop._tcp", NULL, NULL, port, MDNS_RECORD_WITH_METADATA,
NULL);
} else {
#endif
debug(1, "Avahi without metadata");
ret = avahi_entry_group_add_service(group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0, name,
"_raop._tcp", NULL, NULL, port,
MDNS_RECORD_WITHOUT_METADATA, NULL);
#ifdef CONFIG_METADATA
}
#endif

if (ret < 0)
warn("avahi_entry_group_add_service failed");
else {
ret = avahi_entry_group_commit(group);
if (ret < 0)
warn("avahi_entry_group_commit failed");
}
}
#endif

if (ret < 0)
die("avahi_entry_group_add_service failed");

ret = avahi_entry_group_commit(group);
if (ret < 0)
die("avahi_entry_group_commit failed");
}

static void client_callback(AvahiClient *c, AvahiClientState state,
Expand All @@ -99,7 +102,8 @@ static void client_callback(AvahiClient *c, AvahiClientState state,

case AVAHI_CLIENT_FAILURE:
case AVAHI_CLIENT_S_COLLISION:
die("avahi client failure");
debug(1,"avahi client failure");
break;

case AVAHI_CLIENT_CONNECTING:
break;
Expand Down

0 comments on commit 7b3694d

Please sign in to comment.