static void server_callback(AvahiServer *s, AvahiServerState state, AVAHI_GCC_UNUSED void * userdata) { assert(s); /* Called whenever the server state changes */ switch (state) { case AVAHI_SERVER_RUNNING: /* The serve has startup successfully and registered its host * name on the network, so it's time to create our services */ if (!group) create_services(s); break; case AVAHI_SERVER_COLLISION: { char *n; int r; /* A host name collision happened. Let's pick a new name for the server */ n = avahi_alternative_host_name(avahi_server_get_host_name(s)); fprintf(stderr, "Host name collision, retrying with '%s'\n", n); r = avahi_server_set_host_name(s, n); avahi_free(n); if (r < 0) { fprintf(stderr, "Failed to set new host name: %s\n", avahi_strerror(r)); avahi_simple_poll_quit(simple_poll); return; } } /* Fall through */ case AVAHI_SERVER_REGISTERING: /* Let's drop our registered services. When the server is back * in AVAHI_SERVER_RUNNING state we will register them * again with the new host name. */ if (group) avahi_s_entry_group_reset(group); break; case AVAHI_SERVER_FAILURE: /* Terminate on failure */ fprintf(stderr, "Server failure: %s\n", avahi_strerror(avahi_server_errno(s))); avahi_simple_poll_quit(simple_poll); break; case AVAHI_SERVER_INVALID: ; } }
void ControllerDiscoveryMDNS::avahi_server_callback( AvahiServer * server, AvahiServerState state, void * userdata ) { ControllerDiscoveryMDNS * self = ( ControllerDiscoveryMDNS * )userdata; switch ( state ) { case AVAHI_SERVER_RUNNING: { self->create_service( server ); break; } case AVAHI_SERVER_COLLISION: { char * new_name = avahi_alternative_host_name( avahi_server_get_host_name( server ) ); (void)avahi_server_set_host_name( server, new_name ); avahi_free( new_name ); // TODO : check ret break; } case AVAHI_SERVER_REGISTERING: { if ( self->group ) { avahi_s_entry_group_reset( self->group ); } break; } case AVAHI_SERVER_FAILURE: { g_warning( "AVAHI SERVER FAILURE : %s", avahi_strerror( avahi_server_errno( server ) ) ); break; } case AVAHI_SERVER_INVALID: { break; } } }
static void server_callback(AvahiServer *s, AvahiServerState state, void *userdata) { DaemonConfig *c = userdata; assert(s); assert(c); /* This function is possibly called before the global variable * avahi_server has been set, therefore we do it explicitly */ avahi_server = s; #ifdef HAVE_DBUS if (c->enable_dbus && state != AVAHI_SERVER_INVALID && state != AVAHI_SERVER_FAILURE) dbus_protocol_server_state_changed(state); #endif switch (state) { case AVAHI_SERVER_RUNNING: avahi_log_info("Server startup complete. Host name is %s. Local service cookie is %u.", avahi_server_get_host_name_fqdn(s), avahi_server_get_local_service_cookie(s)); sd_notifyf(0, "STATUS=Server startup complete. Host name is %s. Local service cookie is %u.", avahi_server_get_host_name_fqdn(s), avahi_server_get_local_service_cookie(s)); avahi_set_proc_title(argv0, "%s: running [%s]", argv0, avahi_server_get_host_name_fqdn(s)); static_service_add_to_server(); static_hosts_add_to_server(); remove_dns_server_entry_groups(); if (c->publish_resolv_conf && resolv_conf_name_servers && resolv_conf_name_servers[0]) resolv_conf_entry_group = add_dns_servers(s, resolv_conf_entry_group, resolv_conf_name_servers); if (c->publish_dns_servers && c->publish_dns_servers[0]) dns_servers_entry_group = add_dns_servers(s, dns_servers_entry_group, c->publish_dns_servers); simple_protocol_restart_queries(); break; case AVAHI_SERVER_COLLISION: { char *n; static_service_remove_from_server(); static_hosts_remove_from_server(); remove_dns_server_entry_groups(); n = avahi_alternative_host_name(avahi_server_get_host_name(s)); avahi_log_warn("Host name conflict, retrying with %s", n); sd_notifyf(0, "STATUS=Host name conflict, retrying with %s", n); avahi_set_proc_title(argv0, "%s: collision [%s]", argv0, n); avahi_server_set_host_name(s, n); avahi_free(n); break; } case AVAHI_SERVER_FAILURE: avahi_log_error("Server error: %s", avahi_strerror(avahi_server_errno(s))); sd_notifyf(0, "STATUS=Server error: %s", avahi_strerror(avahi_server_errno(s))); avahi_simple_poll_quit(simple_poll_api); break; case AVAHI_SERVER_REGISTERING: sd_notifyf(0, "STATUS=Registering host name %s", avahi_server_get_host_name_fqdn(s)); avahi_set_proc_title(argv0, "%s: registering [%s]", argv0, avahi_server_get_host_name_fqdn(s)); static_service_remove_from_server(); static_hosts_remove_from_server(); remove_dns_server_entry_groups(); break; case AVAHI_SERVER_INVALID: break; } }