mirror of
https://github.com/containers/podman.git
synced 2025-07-31 20:32:39 +08:00
Improve systemd-resolved detection
When 127.0.0.53 is the only nameserver in /etc/resolv.conf assume systemd-resolved is used. This is better because /etc/resolv.conf does not have to be symlinked to /run/systemd/resolve/stub-resolv.conf in order to use systemd-resolved. [NO TESTS NEEDED] Fixes: #10570 Signed-off-by: Paul Holzinger <pholzing@redhat.com>
This commit is contained in:
@ -1650,22 +1650,20 @@ func (c *Container) generateResolvConf() (string, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Determine the endpoint for resolv.conf in case it is a symlink
|
contents, err := ioutil.ReadFile(resolvConf)
|
||||||
resolvPath, err := filepath.EvalSymlinks(resolvConf)
|
|
||||||
// resolv.conf doesn't have to exists
|
// resolv.conf doesn't have to exists
|
||||||
if err != nil && !os.IsNotExist(err) {
|
if err != nil && !os.IsNotExist(err) {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Determine if symlink points to any of the systemd-resolved files
|
ns := resolvconf.GetNameservers(contents)
|
||||||
if strings.HasPrefix(resolvPath, "/run/systemd/resolve/") {
|
// check if systemd-resolved is used, assume it is used when 127.0.0.53 is the only nameserver
|
||||||
resolvPath = "/run/systemd/resolve/resolv.conf"
|
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")
|
||||||
contents, err := ioutil.ReadFile(resolvPath)
|
if err != nil {
|
||||||
// resolv.conf doesn't have to exists
|
return "", errors.Wrapf(err, "detected that systemd-resolved is in use, but could not locate real resolv.conf")
|
||||||
if err != nil && !os.IsNotExist(err) {
|
}
|
||||||
return "", err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ipv6 := false
|
ipv6 := false
|
||||||
|
Reference in New Issue
Block a user