diff options
author | Paul Holzinger <pholzing@redhat.com> | 2021-06-08 11:28:46 +0200 |
---|---|---|
committer | Matthew Heon <mheon@redhat.com> | 2021-06-11 13:06:06 -0400 |
commit | 8ba0c92e6a8da59417d7e96a6f2002bfe1a74f1f (patch) | |
tree | 88eb3a951d4506ac690d7ec97f6edfbaaf4e5b6c /libpod | |
parent | c3f6ef63a27ae23f79995c4019d552ed4dfdd406 (diff) | |
download | podman-8ba0c92e6a8da59417d7e96a6f2002bfe1a74f1f.tar.gz podman-8ba0c92e6a8da59417d7e96a6f2002bfe1a74f1f.tar.bz2 podman-8ba0c92e6a8da59417d7e96a6f2002bfe1a74f1f.zip |
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>
Diffstat (limited to 'libpod')
-rw-r--r-- | libpod/container_internal_linux.go | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/libpod/container_internal_linux.go b/libpod/container_internal_linux.go index bf235e42c..be59e3b54 100644 --- a/libpod/container_internal_linux.go +++ b/libpod/container_internal_linux.go @@ -1649,22 +1649,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 |