mirror of
https://github.com/tailscale/tailscale.git
synced 2025-08-13 22:47:30 +00:00
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:

committed by
Dave Anderson

parent
04d24d3a38
commit
a320d70614
@@ -186,8 +186,20 @@ func (m memFS) ReadFile(name string) ([]byte, error) {
|
||||
panic("TODO")
|
||||
}
|
||||
|
||||
func (fs memFS) WriteFile(name string, contents []byte, perm os.FileMode) error {
|
||||
fs[name] = string(contents)
|
||||
func (m memFS) Truncate(name string) error {
|
||||
v, ok := m[name]
|
||||
if !ok {
|
||||
return fs.ErrNotExist
|
||||
}
|
||||
if s, ok := v.(string); ok {
|
||||
m[name] = s[:0]
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m memFS) WriteFile(name string, contents []byte, perm os.FileMode) error {
|
||||
m[name] = string(contents)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user