From: Jörg Krause Date: Thu, 24 Nov 2016 13:48:03 +0000 (+0100) Subject: mdns: avahi: handle avahi client failure X-Git-Tag: 3.0.d18~11^2 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F428%2Fhead;p=thirdparty%2Fshairport-sync.git mdns: avahi: handle avahi client failure Handle the avahi client failure so that in case of a restart of the avahi daemon the shairport-sync daemon has not to be restarted, too. The handling is based on the error handling of avahi-publish [1]. [1] https://github.com/lathiat/avahi/blob/master/avahi-utils/avahi-publish.c#L156-L179 --- diff --git a/mdns_avahi.c b/mdns_avahi.c index 7fe6c187..b9664674 100644 --- a/mdns_avahi.c +++ b/mdns_avahi.c @@ -234,6 +234,8 @@ static void register_service(AvahiClient *c) { static void client_callback(AvahiClient *c, AvahiClientState state, AVAHI_GCC_UNUSED void *userdata) { + int err; + switch (state) { case AVAHI_CLIENT_S_REGISTERING: if (group) @@ -245,7 +247,25 @@ static void client_callback(AvahiClient *c, AvahiClientState state, break; case AVAHI_CLIENT_FAILURE: - debug(1, "avahi: client failure"); + err = avahi_client_errno(c); + debug(1, "avahi: client failure: %s", avahi_strerror(err)); + + if (err == AVAHI_ERR_DISCONNECTED) { + /* We have been disconnected, so lets reconnect */ + avahi_client_free(c); + c = NULL; + group = NULL; + + if (!(client = avahi_client_new(avahi_threaded_poll_get(tpoll), + AVAHI_CLIENT_NO_FAIL, client_callback, + userdata, &err))) { + warn("avahi: failed to create client object: %s", avahi_strerror(err)); + avahi_threaded_poll_quit(tpoll); + } + } else { + warn("avahi: client failure: %s", avahi_strerror(err)); + avahi_threaded_poll_quit(tpoll); + } break; case AVAHI_CLIENT_S_COLLISION: