watcher: do not run initial sync in background

Signed-off-by: Steffen Vogel <post@steffenvogel.de>
This commit is contained in:
Steffen Vogel
2022-09-06 03:14:49 +02:00
parent fd651131b0
commit 3fca8e23dc
4 changed files with 15 additions and 11 deletions

View File

@@ -1,3 +1,4 @@
# An interval at which wice will periodically check for added, removed or modified WireGuard interfaces.
watch_interval: 1s
community: "some-common-password"

View File

@@ -300,7 +300,7 @@ func NewInterface(wgDev *wgtypes.Device, client *wgctrl.Client) (*Interface, err
}
if i.KernelDevice, err = device.FindDevice(wgDev.Name); err != nil {
return nil, err
return nil, fmt.Errorf("failed to find kernel device: %w", err)
}
i.logger.Info("Added interface",

View File

@@ -106,7 +106,13 @@ func (d *Daemon) Run() error {
signals := util.SetupSignals(util.SigUpdate)
go d.Watcher.Run()
d.logger.Debug("Started initial synchronization")
if err := d.Watcher.Sync(); err != nil {
d.logger.Fatal("Initial synchronization failed", zap.Error(err))
}
d.logger.Debug("Finished initial synchronization")
go d.Watcher.Watch()
out:
for {

View File

@@ -94,13 +94,7 @@ func (w *Watcher) Close() error {
return nil
}
func (w *Watcher) Run() {
w.logger.Debug("Started initial synchronization")
if err := w.Sync(); err != nil {
w.logger.Fatal("Initial synchronization failed", zap.Error(err))
}
w.logger.Debug("Finished initial synchronization")
func (w *Watcher) Watch() {
if err := w.watchUser(); err != nil {
w.logger.Fatal("Failed to watch userspace interfaces", zap.Error(err))
}
@@ -111,8 +105,11 @@ func (w *Watcher) Run() {
}
w.logger.Debug("Started watching for changes of WireGuard kernel devices")
ticker := time.NewTicker(w.interval)
defer ticker.Stop()
ticker := &time.Ticker{}
if w.interval > 0 {
ticker = time.NewTicker(w.interval)
defer ticker.Stop()
}
out:
for {