From 06e2202a4cc6d9a0f382a0bbdcdbd2d527734d5f Mon Sep 17 00:00:00 2001 From: Pierre Imai Date: Fri, 6 May 2016 17:56:57 +0900 Subject: [PATCH] Always update search domain paths. _resolv_set_nameservers_for_net() so far did not update the search paths, unless the servers changed as well. BUG: 28437641 Change-Id: Id31f2d97c173e00357fb2ba95908afb4572c0fc1 --- libc/dns/resolv/res_cache.c | 68 ++++++++++++++++++++++++--------------------- 1 file changed, 36 insertions(+), 32 deletions(-) diff --git a/libc/dns/resolv/res_cache.c b/libc/dns/resolv/res_cache.c index 212ee0a1f..ad2c5c01d 100644 --- a/libc/dns/resolv/res_cache.c +++ b/libc/dns/resolv/res_cache.c @@ -2010,29 +2010,6 @@ _resolv_set_nameservers_for_net(unsigned netid, const char** servers, unsigned n } cache_info->nscount = numservers; - // code moved from res_init.c, load_domain_search_list - strlcpy(cache_info->defdname, domains, sizeof(cache_info->defdname)); - if ((cp = strchr(cache_info->defdname, '\n')) != NULL) - *cp = '\0'; - - cp = cache_info->defdname; - offset = cache_info->dnsrch_offset; - while (offset < cache_info->dnsrch_offset + MAXDNSRCH) { - while (*cp == ' ' || *cp == '\t') /* skip leading white space */ - cp++; - if (*cp == '\0') /* stop if nothing more to do */ - break; - *offset++ = cp - cache_info->defdname; /* record this search domain */ - while (*cp) { /* zero-terminate it */ - if (*cp == ' '|| *cp == '\t') { - *cp++ = '\0'; - break; - } - cp++; - } - } - *offset = -1; /* cache_info->dnsrch_offset has MAXDNSRCH+1 items */ - // Flush the cache and reset the stats. _flush_cache_for_net_locked(netid); @@ -2041,15 +2018,42 @@ _resolv_set_nameservers_for_net(unsigned netid, const char** servers, unsigned n // max_samples actually change, in practice the overhead of checking is higher than the // cost, and overflows are unlikely ++cache_info->revision_id; - } else if (cache_info->params.max_samples != old_max_samples) { - // If the maximum number of samples changes, the overhead of keeping the most recent - // samples around is not considered worth the effort, so they are cleared instead. All - // other parameters do not affect shared state: Changing these parameters does not - // invalidate the samples, as they only affect aggregation and the conditions under which - // servers are considered usable. - _res_cache_clear_stats_locked(cache_info); - ++cache_info->revision_id; - } + } else if (cache_info->params.max_samples != old_max_samples) { + // If the maximum number of samples changes, the overhead of keeping the most recent + // samples around is not considered worth the effort, so they are cleared instead. All + // other parameters do not affect shared state: Changing these parameters does not + // invalidate the samples, as they only affect aggregation and the conditions under + // which servers are considered usable. + _res_cache_clear_stats_locked(cache_info); + ++cache_info->revision_id; + } + + // Always update the search paths, since determining whether they actually changed is + // complex due to the zero-padding, and probably not worth the effort. Cache-flushing + // however is not // necessary, since the stored cache entries do contain the domain, not + // just the host name. + // code moved from res_init.c, load_domain_search_list + strlcpy(cache_info->defdname, domains, sizeof(cache_info->defdname)); + if ((cp = strchr(cache_info->defdname, '\n')) != NULL) + *cp = '\0'; + + cp = cache_info->defdname; + offset = cache_info->dnsrch_offset; + while (offset < cache_info->dnsrch_offset + MAXDNSRCH) { + while (*cp == ' ' || *cp == '\t') /* skip leading white space */ + cp++; + if (*cp == '\0') /* stop if nothing more to do */ + break; + *offset++ = cp - cache_info->defdname; /* record this search domain */ + while (*cp) { /* zero-terminate it */ + if (*cp == ' '|| *cp == '\t') { + *cp++ = '\0'; + break; + } + cp++; + } + } + *offset = -1; /* cache_info->dnsrch_offset has MAXDNSRCH+1 items */ } pthread_mutex_unlock(&_res_cache_list_lock); -- 2.11.0