diff options
author | benizi <benizi@gmail.com> | 2009-04-14 03:10:54 +0000 |
---|---|---|
committer | benizi <benizi@gmail.com> | 2009-04-14 03:10:54 +0000 |
commit | 527605289910a15f5a3e9dff29a2d429820772ae (patch) | |
tree | e9ec32be56201ed27df6a4d743661c5a5b694823 | |
parent | d70d3082d5579c679a959d996bb910439b0a1f1d (diff) | |
download | distcc-git-527605289910a15f5a3e9dff29a2d429820772ae.tar.gz |
Remove duplicate hosts from the zeroconf list.
Fixes issue 43 <http://code.google.com/p/distcc/issues/detail?id=43>.
As mentioned in issue 34 <http://code.google.com/p/distcc/issues/detail?id=34>,
hosts with both IPv4 and IPv6 addresses showed up twice if avahi is
IPv6-enabled. So, filter out duplicates using the service name.
-rw-r--r-- | src/zeroconf.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/zeroconf.c b/src/zeroconf.c index fc72177..0de0957 100644 --- a/src/zeroconf.c +++ b/src/zeroconf.c @@ -129,6 +129,8 @@ static time_t fd_last_used(int fd, time_t clip_time) { return now - ft; } +static void remove_duplicate_services(struct daemon_data *d); + /* Write host data to host file */ static int write_hosts(struct daemon_data *d) { struct host *h; @@ -152,6 +154,8 @@ static int write_hosts(struct daemon_data *d) { return -1; } + remove_duplicate_services(d); + for (h = d->hosts; h; h = h->next) { char t[256], a[AVAHI_ADDRESS_STR_MAX]; @@ -190,6 +194,26 @@ static void free_host(struct host *h) { free(h); } +/* Remove hosts with duplicate service names from the host list. + * Hosts with multiple IP addresses show up more than once, but + * should all have the same service name: "distcc@hostname" */ +static void remove_duplicate_services(struct daemon_data *d) { + struct host *host1, *host2, *prev; + assert(d); + for (host1 = d->hosts; host1; host1 = host1->next) { + assert(host1->service); + for (host2 = host1->next, prev = host1; host2; host2 = prev->next) { + assert(host2->service); + if (!strcmp(host1->service, host2->service)) { + prev->next = host2->next; + free_host(host2); + } else { + prev = host2; + } + } + } +} + /* Remove a service from the host list */ static void remove_service(struct daemon_data *d, AvahiIfIndex interface, AvahiProtocol protocol, const char *name, const char *domain) { struct host *h, *p = NULL; |