Skip to content

Commit

Permalink
Merge pull request #10598 from Luap99/systemd-resolved
Browse files Browse the repository at this point in the history
Improve systemd-resolved detection
  • Loading branch information
openshift-merge-robot authored Jun 8, 2021
2 parents 3d961ac + 18fa124 commit 9edd08c
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions libpod/container_internal_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -1650,22 +1650,20 @@ func (c *Container) generateResolvConf() (string, error) {
}
}

// Determine the endpoint for resolv.conf in case it is a symlink
resolvPath, err := filepath.EvalSymlinks(resolvConf)
contents, err := ioutil.ReadFile(resolvConf)
// resolv.conf doesn't have to exists
if err != nil && !os.IsNotExist(err) {
return "", err
}

// Determine if symlink points to any of the systemd-resolved files
if strings.HasPrefix(resolvPath, "/run/systemd/resolve/") {
resolvPath = "/run/systemd/resolve/resolv.conf"
}

contents, err := ioutil.ReadFile(resolvPath)
// resolv.conf doesn't have to exists
if err != nil && !os.IsNotExist(err) {
return "", err
ns := resolvconf.GetNameservers(contents)
// check if systemd-resolved is used, assume it is used when 127.0.0.53 is the only nameserver
if len(ns) == 1 && ns[0] == "127.0.0.53" {
// read the actual resolv.conf file for systemd-resolved
contents, err = ioutil.ReadFile("/run/systemd/resolve/resolv.conf")
if err != nil {
return "", errors.Wrapf(err, "detected that systemd-resolved is in use, but could not locate real resolv.conf")
}
}

ipv6 := false
Expand Down

0 comments on commit 9edd08c

Please sign in to comment.