OSDN Git Service

Always update search domain paths.
authorPierre Imai <imaipi@google.com>
Fri, 6 May 2016 08:56:57 +0000 (17:56 +0900)
committerPierre Imai <imaipi@google.com>
Wed, 11 May 2016 02:06:55 +0000 (11:06 +0900)
_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

index 212ee0a..ad2c5c0 100644 (file)
@@ -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);