netconfig: move /tmp/resolv.conf symlink out of the way

Commit 0f75b1cbef6d0ec4853a6a02d96d4b57ce478769 was incomplete.
This commit is contained in:
Michael Stapelberg 2025-01-27 08:26:03 +01:00
parent 0f75b1cbef
commit 13e1c1bbb4

View File

@ -441,8 +441,17 @@ func createResolvConfIfMissing(root, contents string) error {
// Explicitly check for the file's existance
// just so that we can avoid printing an error
// in the normal case (file exists).
if _, err := os.Stat(fn); err == nil {
return nil // file already exists, do not overwrite
st, err := os.Lstat(fn)
if err == nil {
if st.Mode()&os.ModeSymlink != 0 {
// File is a symbolic link (at boot, gokrazy links /tmp/resolv.conf to /proc/net/pnp).
// Delete the link and fallthrough to create the file.
if err := os.Remove(fn); err != nil {
return err
}
} else {
return nil // regular file already exists, do not overwrite
}
} else if !os.IsNotExist(err) {
return err // unexpected error
}