Created
March 26, 2016 22:34
-
-
Save AudriusButkevicius/fa15aa48ab9ece7407a1 to your computer and use it in GitHub Desktop.
Golang Android DNS patch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/net/conf.go b/src/net/conf.go | |
index 36566a4..42ff1c5 100644 | |
--- a/src/net/conf.go | |
+++ b/src/net/conf.go | |
@@ -96,7 +96,7 @@ func initConfVal() { | |
confVal.nss = parseNSSConfFile("/etc/nsswitch.conf") | |
} | |
- confVal.resolv = dnsReadConfig("/etc/resolv.conf") | |
+ confVal.resolv = dnsReadConfig(resolvConfPath) | |
if confVal.resolv.err != nil && !os.IsNotExist(confVal.resolv.err) && | |
!os.IsPermission(confVal.resolv.err) { | |
// If we can't read the resolv.conf file, assume it | |
diff --git a/src/net/dnsclient_unix.go b/src/net/dnsclient_unix.go | |
index 736e573..a0028d0 100644 | |
--- a/src/net/dnsclient_unix.go | |
+++ b/src/net/dnsclient_unix.go | |
@@ -17,6 +17,7 @@ package net | |
import ( | |
"errors" | |
+ "fmt" | |
"io" | |
"math/rand" | |
"os" | |
@@ -29,7 +30,18 @@ type dnsDialer interface { | |
dialDNS(string, string) (dnsConn, error) | |
} | |
-var testHookDNSDialer = func(d time.Duration) dnsDialer { return &Dialer{Timeout: d} } | |
+var ( | |
+ testHookDNSDialer = func(d time.Duration) dnsDialer { return &Dialer{Timeout: d} } | |
+ resolvConfPath = "/etc/resolv.conf" | |
+) | |
+ | |
+func init() { | |
+ path := os.Getenv("ANDROID_RESOLV_CONF") | |
+ if path != "" { | |
+ fmt.Println("Overriding resolv.conf path", path) | |
+ resolvConfPath = path | |
+ } | |
+} | |
// A dnsConn represents a DNS transport endpoint. | |
type dnsConn interface { | |
@@ -242,7 +254,7 @@ func (conf *resolverConfig) init() { | |
// resolv.conf twice the first time. | |
conf.dnsConfig = systemConf().resolv | |
if conf.dnsConfig == nil { | |
- conf.dnsConfig = dnsReadConfig("/etc/resolv.conf") | |
+ conf.dnsConfig = dnsReadConfig(resolvConfPath) | |
} | |
conf.lastChecked = time.Now() | |
@@ -300,7 +312,7 @@ func lookup(name string, qtype uint16) (cname string, rrs []dnsRR, err error) { | |
if !isDomainName(name) { | |
return "", nil, &DNSError{Err: "invalid domain name", Name: name} | |
} | |
- resolvConf.tryUpdate("/etc/resolv.conf") | |
+ resolvConf.tryUpdate(resolvConfPath) | |
resolvConf.mu.RLock() | |
conf := resolvConf.dnsConfig | |
resolvConf.mu.RUnlock() | |
@@ -434,7 +446,7 @@ func goLookupIPOrder(name string, order hostLookupOrder) (addrs []IPAddr, err er | |
if !isDomainName(name) { | |
return nil, &DNSError{Err: "invalid domain name", Name: name} | |
} | |
- resolvConf.tryUpdate("/etc/resolv.conf") | |
+ resolvConf.tryUpdate(resolvConfPath) | |
resolvConf.mu.RLock() | |
conf := resolvConf.dnsConfig | |
resolvConf.mu.RUnlock() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment