diff --git a/respond/daemon/config.go b/respond/daemon/config.go index 9bff26e..ebfd0e8 100644 --- a/respond/daemon/config.go +++ b/respond/daemon/config.go @@ -3,6 +3,7 @@ package respondd import ( "io/ioutil" "strings" + "sync" "github.com/FreifunkBremen/yanic/data" "github.com/FreifunkBremen/yanic/lib/duration" @@ -26,6 +27,7 @@ type Daemon struct { Babel string `toml:"babel"` babelData *babelState.BabelState `toml:"-"` + dataMX sync.Mutex dataByInterface map[string]*data.ResponseData Answer *AnswerConfig `toml:"defaults"` diff --git a/respond/daemon/data.go b/respond/daemon/data.go index 51b1ef3..839bf01 100644 --- a/respond/daemon/data.go +++ b/respond/daemon/data.go @@ -22,6 +22,8 @@ func (d *Daemon) updateData() { } func (d *Daemon) getData(iface string) *data.ResponseData { + d.dataMX.Lock() + defer d.dataMX.Unlock() if iData, ok := d.dataByInterface[iface]; ok { return iData } diff --git a/respond/daemon/main.go b/respond/daemon/main.go index ac25176..10c9f57 100644 --- a/respond/daemon/main.go +++ b/respond/daemon/main.go @@ -16,7 +16,9 @@ func (d *Daemon) Start() { d.AnswerByZones = make(map[string]*AnswerConfig) } + d.dataMX.Lock() d.updateData() + d.dataMX.Unlock() go d.updateWorker() if d.Babel != "" { @@ -69,6 +71,8 @@ func (d *Daemon) updateWorker() { c := time.Tick(d.DataInterval.Duration) for range c { + d.dataMX.Lock() d.updateData() + d.dataMX.Unlock() } }