net/dns: fall back to copy+delete/truncate if moving to/from /etc/resolv.conf fails.

In some containers, /etc/resolv.conf is a bind-mount from outside the container.
This prevents renaming to or from /etc/resolv.conf, because it's on a different
filesystem from linux's perspective. It also prevents removing /etc/resolv.conf,
because doing so would break the bind-mount.

If we find ourselves within this environment, fall back to using copy+delete when
renaming to /etc/resolv.conf, and copy+truncate when renaming from /etc/resolv.conf.

Fixes #3000

Co-authored-by: Denton Gentry <dgentry@tailscale.com>
Signed-off-by: David Anderson <danderson@tailscale.com>
This commit is contained in:
David Anderson
2021-10-06 17:49:32 -07:00
committed by Dave Anderson
parent 04d24d3a38
commit a320d70614
8 changed files with 173 additions and 44 deletions

View File

@ -68,7 +68,7 @@ func isResolvedActive() bool {
return false
}
config, err := newDirectManager().readResolvFile(resolvConf)
config, err := newDirectManager(logger.Discard).readResolvFile(resolvConf)
if err != nil {
return false
}