mirror of
https://codeberg.org/cunicu/cunicu.git
synced 2025-09-26 21:01:14 +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
|
||||
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 {
|
||||
return nil, err
|
||||
return nil, fmt.Errorf("failed to find kernel device: %w", err)
|
||||
}
|
||||
|
||||
i.logger.Info("Added interface",
|
||||
|
@@ -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 {
|
||||
|
@@ -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 {
|
||||
|
Reference in New Issue
Block a user