From 13e1c1bbb47bbd04bd8dbda646ee213a15b18fe4 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Mon, 27 Jan 2025 08:26:03 +0100 Subject: [PATCH] netconfig: move /tmp/resolv.conf symlink out of the way Commit 0f75b1cbef6d0ec4853a6a02d96d4b57ce478769 was incomplete. --- internal/netconfig/netconfig.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/internal/netconfig/netconfig.go b/internal/netconfig/netconfig.go index 9488dd0..7675453 100644 --- a/internal/netconfig/netconfig.go +++ b/internal/netconfig/netconfig.go @@ -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 }