From 735ed7ab349beec035be0f97f9f6548b90276e4e Mon Sep 17 00:00:00 2001 From: Zoltan Papp Date: Mon, 6 May 2024 17:01:00 +0200 Subject: [PATCH] Fix resolv.conf repairer logic (#1931) Stop the file repairer before doing the restore --- client/internal/dns/file_linux.go | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/client/internal/dns/file_linux.go b/client/internal/dns/file_linux.go index b427a30e1..b9d6d699d 100644 --- a/client/internal/dns/file_linux.go +++ b/client/internal/dns/file_linux.go @@ -47,24 +47,20 @@ func (f *fileConfigurator) supportCustomPort() bool { } func (f *fileConfigurator) applyDNSConfig(config HostDNSConfig) error { - backupFileExist := false - _, err := os.Stat(fileDefaultResolvConfBackupLocation) - if err == nil { - backupFileExist = true - } - + backupFileExist := f.isBackupFileExist() if !config.RouteAll { if backupFileExist { - err = f.restore() + f.repair.stopWatchFileChanges() + err := f.restore() if err != nil { - return fmt.Errorf("unable to configure DNS for this peer using file manager without a Primary nameserver group. Restoring the original file return err: %w", err) + return fmt.Errorf("restoring the original resolv.conf file return err: %w", err) } } return fmt.Errorf("unable to configure DNS for this peer using file manager without a nameserver group with all domains configured") } if !backupFileExist { - err = f.backup() + err := f.backup() if err != nil { return fmt.Errorf("unable to backup the resolv.conf file: %w", err) } @@ -184,6 +180,11 @@ func (f *fileConfigurator) restoreUncleanShutdownDNS(storedDNSAddress *netip.Add return nil } +func (f *fileConfigurator) isBackupFileExist() bool { + _, err := os.Stat(fileDefaultResolvConfBackupLocation) + return err == nil +} + func restoreResolvConfFile() error { log.Debugf("restoring unclean shutdown: restoring %s from %s", defaultResolvConfPath, fileUncleanShutdownResolvConfLocation)