From e033558d7027a40a6996c08b5125e45141192071 Mon Sep 17 00:00:00 2001 From: Eugene Burkov Date: Fri, 14 Jun 2024 14:39:58 +0300 Subject: [PATCH] all: add & use empty fswatcher --- CHANGELOG.md | 5 +++++ internal/aghos/fswatcher.go | 27 +++++++++++++++++++++++++++ internal/home/home.go | 4 +++- 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fa0f3512c6d..7b34dbb2cf3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,11 @@ NOTE: Add new changes BELOW THIS COMMENT. - Node 18 support, Node 20 will be required in future releases. +### Fixed + +- Tracking `/etc/hosts` file changes causing panics within particular + filesystems on start ([#7076]). + diff --git a/internal/aghos/fswatcher.go b/internal/aghos/fswatcher.go index 9f3a657046d..5cb1b1c5800 100644 --- a/internal/aghos/fswatcher.go +++ b/internal/aghos/fswatcher.go @@ -160,3 +160,30 @@ func (w *osWatcher) handleErrors() { log.Error("%s: %s", osWatcherPref, err) } } + +// EmptyFSWatcher is a no-op implementation of the [FSWatcher] interface. It +// may be used on systems not supporting filesystem events. +type EmptyFSWatcher struct{} + +// type check +var _ FSWatcher = EmptyFSWatcher{} + +// Start implements the [FSWatcher] interface for EmptyFSWatcher. +func (EmptyFSWatcher) Start() (err error) { + return nil +} + +// Close implements the [FSWatcher] interface for EmptyFSWatcher. +func (EmptyFSWatcher) Close() (err error) { + return nil +} + +// Events implements the [FSWatcher] interface for EmptyFSWatcher. +func (EmptyFSWatcher) Events() (e <-chan event) { + return nil +} + +// Add implements the [FSWatcher] interface for EmptyFSWatcher. +func (EmptyFSWatcher) Add(_ string) (err error) { + return nil +} diff --git a/internal/home/home.go b/internal/home/home.go index 93e8e09d123..fc64f3766dd 100644 --- a/internal/home/home.go +++ b/internal/home/home.go @@ -232,7 +232,9 @@ func configureOS(conf *configuration) (err error) { func setupHostsContainer() (err error) { hostsWatcher, err := aghos.NewOSWritesWatcher() if err != nil { - return fmt.Errorf("initing hosts watcher: %w", err) + log.Info("WARNING: initializing filesystem watcher: %s; not watching for changes", err) + + hostsWatcher = aghos.EmptyFSWatcher{} } paths, err := hostsfile.DefaultHostsPaths()