Fix: DNS_KEEP_NAMESERVER

This commit is contained in:
Quentin McGaw
2021-01-06 21:57:16 +00:00
parent 89bd10fc33
commit 5bd99b9f35
2 changed files with 88 additions and 23 deletions
+9 -1
View File
@@ -26,7 +26,7 @@ func (c *configurator) UseDNSInternally(ip net.IP) {
func (c *configurator) UseDNSSystemWide(ip net.IP, keepNameserver bool) error {
c.logger.Info("using DNS address %s system wide", ip.String())
const filepath = string(constants.ResolvConf)
file, err := c.openFile(filepath, os.O_RDWR|os.O_TRUNC, 0644)
file, err := c.openFile(filepath, os.O_RDONLY, 0)
if err != nil {
return err
}
@@ -35,6 +35,9 @@ func (c *configurator) UseDNSSystemWide(ip net.IP, keepNameserver bool) error {
_ = file.Close()
return err
}
if err := file.Close(); err != nil {
return err
}
s := strings.TrimSuffix(string(data), "\n")
@@ -50,6 +53,11 @@ func (c *configurator) UseDNSSystemWide(ip net.IP, keepNameserver bool) error {
}
s = strings.Join(lines, "\n") + "\n"
file, err = c.openFile(filepath, os.O_WRONLY|os.O_TRUNC, 0644)
if err != nil {
return err
}
_, err = file.WriteString(s)
if err != nil {
_ = file.Close()