Pārlūkot izejas kodu

libnetwork: sandbox.rebuildDNS() move variables closer to where they're used

Some of these options required parsing the resolv.conf file, but the function
could return an error further down; this patch moves the parsing closer to
where their results are used (which may not happen if we're encountering an
error before).

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sebastiaan van Stijn 2 gadi atpakaļ
vecāks
revīzija
806b4fbcad
1 mainītis faili ar 7 papildinājumiem un 8 dzēšanām
  1. 7 8
      libnetwork/sandbox_dns_unix.go

+ 7 - 8
libnetwork/sandbox_dns_unix.go

@@ -368,19 +368,12 @@ func (sb *sandbox) rebuildDNS() error {
 	if len(sb.extDNS) == 0 {
 		sb.setExternalResolvers(currRC, resolvconf.IPv4, false)
 	}
-	var (
-		dnsList        = []string{sb.resolver.NameServer()}
-		dnsOptionsList = resolvconf.GetOptions(currRC)
-		dnsSearchList  = resolvconf.GetSearchDomains(currRC)
-	)
-
-	// external v6 DNS servers has to be listed in resolv.conf
-	dnsList = append(dnsList, resolvconf.GetNameservers(currRC, resolvconf.IPv6)...)
 
 	// If the user config and embedded DNS server both have ndots option set,
 	// remember the user's config so that unqualified names not in the docker
 	// domain can be dropped.
 	resOptions := sb.resolver.ResolverOptions()
+	dnsOptionsList := resolvconf.GetOptions(currRC)
 
 dnsOpt:
 	for _, resOpt := range resOptions {
@@ -411,6 +404,12 @@ dnsOpt:
 		dnsOptionsList = append(dnsOptionsList, resOptions...)
 	}
 
+	var (
+		// external v6 DNS servers have to be listed in resolv.conf
+		dnsList       = append([]string{sb.resolver.NameServer()}, resolvconf.GetNameservers(currRC, resolvconf.IPv6)...)
+		dnsSearchList = resolvconf.GetSearchDomains(currRC)
+	)
+
 	_, err = resolvconf.Build(sb.config.resolvConfPath, dnsList, dnsSearchList, dnsOptionsList)
 	return err
 }