Skip to content

Commit

Permalink
- autohosts: fix crash on startup if filesystem watcher couldn't be i…
Browse files Browse the repository at this point in the history
…nitialized
  • Loading branch information
szolin committed Jun 19, 2020
1 parent aa7b3c3 commit ba17a5b
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions util/auto_hosts.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,19 @@ func (a *AutoHosts) Start() {
go a.updateLoop()
a.updateChan <- true

go a.watcherLoop()
if a.watcher != nil {
go a.watcherLoop()

err := a.watcher.Add(a.hostsFn)
if err != nil {
log.Error("Error while initializing watcher for a file %s: %s", a.hostsFn, err)
}

for _, dir := range a.hostsDirs {
err = a.watcher.Add(dir)
err := a.watcher.Add(a.hostsFn)
if err != nil {
log.Error("Error while initializing watcher for a directory %s: %s", dir, err)
log.Error("Error while initializing watcher for a file %s: %s", a.hostsFn, err)
}

for _, dir := range a.hostsDirs {
err = a.watcher.Add(dir)
if err != nil {
log.Error("Error while initializing watcher for a directory %s: %s", dir, err)
}
}
}
}
Expand All @@ -95,7 +97,9 @@ func (a *AutoHosts) Start() {
func (a *AutoHosts) Close() {
a.updateChan <- false
close(a.updateChan)
_ = a.watcher.Close()
if a.watcher != nil {
_ = a.watcher.Close()
}
}

// update table
Expand Down

0 comments on commit ba17a5b

Please sign in to comment.