mirror of
https://codeberg.org/cunicu/cunicu.git
synced 2025-09-27 05:06:02 +08:00
watcher: do not run initial sync in background
Signed-off-by: Steffen Vogel <post@steffenvogel.de>
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
# An interval at which wice will periodically check for added, removed or modified WireGuard interfaces.
|
||||||
watch_interval: 1s
|
watch_interval: 1s
|
||||||
community: "some-common-password"
|
community: "some-common-password"
|
||||||
|
|
||||||
|
@@ -300,7 +300,7 @@ func NewInterface(wgDev *wgtypes.Device, client *wgctrl.Client) (*Interface, err
|
|||||||
}
|
}
|
||||||
|
|
||||||
if i.KernelDevice, err = device.FindDevice(wgDev.Name); err != nil {
|
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",
|
i.logger.Info("Added interface",
|
||||||
|
@@ -106,7 +106,13 @@ func (d *Daemon) Run() error {
|
|||||||
|
|
||||||
signals := util.SetupSignals(util.SigUpdate)
|
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:
|
out:
|
||||||
for {
|
for {
|
||||||
|
@@ -94,13 +94,7 @@ func (w *Watcher) Close() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Watcher) Run() {
|
func (w *Watcher) Watch() {
|
||||||
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")
|
|
||||||
|
|
||||||
if err := w.watchUser(); err != nil {
|
if err := w.watchUser(); err != nil {
|
||||||
w.logger.Fatal("Failed to watch userspace interfaces", zap.Error(err))
|
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")
|
w.logger.Debug("Started watching for changes of WireGuard kernel devices")
|
||||||
|
|
||||||
ticker := time.NewTicker(w.interval)
|
ticker := &time.Ticker{}
|
||||||
defer ticker.Stop()
|
if w.interval > 0 {
|
||||||
|
ticker = time.NewTicker(w.interval)
|
||||||
|
defer ticker.Stop()
|
||||||
|
}
|
||||||
|
|
||||||
out:
|
out:
|
||||||
for {
|
for {
|
||||||
|
Reference in New Issue
Block a user