|
@@ -266,32 +266,43 @@ func monitorEth0PlugCycle(plugCycle chan bool, done chan struct{}) error {
|
|
|
isUp := link.Attrs().Flags&syscall.IFF_RUNNING != 0
|
|
isUp := link.Attrs().Flags&syscall.IFF_RUNNING != 0
|
|
|
waitingForPlug := false
|
|
waitingForPlug := false
|
|
|
|
|
|
|
|
- for u := range updates {
|
|
|
|
|
- if u.Link.Attrs().Name != "eth0" {
|
|
|
|
|
- continue
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ const debounce = 1000 * time.Millisecond
|
|
|
|
|
+ var lastChange time.Time
|
|
|
|
|
|
|
|
- newUp := u.IfInfomsg.Flags&syscall.IFF_RUNNING != 0
|
|
|
|
|
- if newUp == isUp {
|
|
|
|
|
- continue
|
|
|
|
|
- }
|
|
|
|
|
- isUp = newUp
|
|
|
|
|
-
|
|
|
|
|
- if !isUp {
|
|
|
|
|
- baseapp.Logger.Warnf("[%s] ❌ eth0 cable unplugged!", MODULE_NAME)
|
|
|
|
|
- waitingForPlug = true
|
|
|
|
|
- } else if waitingForPlug {
|
|
|
|
|
- baseapp.Logger.Infof("[%s] ✅ eth0 cable plugged in", MODULE_NAME)
|
|
|
|
|
- select {
|
|
|
|
|
- case plugCycle <- true:
|
|
|
|
|
- case <-done:
|
|
|
|
|
- return nil
|
|
|
|
|
|
|
+ ticker := time.NewTicker(500 * time.Millisecond)
|
|
|
|
|
+ defer ticker.Stop()
|
|
|
|
|
+
|
|
|
|
|
+ for {
|
|
|
|
|
+ select {
|
|
|
|
|
+ case u := <-updates:
|
|
|
|
|
+ if u.Link.Attrs().Name != "eth0" {
|
|
|
|
|
+ continue
|
|
|
}
|
|
}
|
|
|
- waitingForPlug = false
|
|
|
|
|
|
|
+ newUp := u.IfInfomsg.Flags&syscall.IFF_RUNNING != 0
|
|
|
|
|
+ if newUp == isUp {
|
|
|
|
|
+ continue
|
|
|
|
|
+ }
|
|
|
|
|
+ isUp = newUp
|
|
|
|
|
+ lastChange = time.Now()
|
|
|
|
|
+
|
|
|
|
|
+ if !isUp {
|
|
|
|
|
+ baseapp.Logger.Warnf("[%s] ❌ eth0 cable unplugged!", MODULE_NAME)
|
|
|
|
|
+ waitingForPlug = true
|
|
|
|
|
+ }
|
|
|
|
|
+ case <-ticker.C:
|
|
|
|
|
+ if waitingForPlug && isUp && time.Since(lastChange) >= debounce {
|
|
|
|
|
+ baseapp.Logger.Infof("[%s] ✅ eth0 cable plugged in", MODULE_NAME)
|
|
|
|
|
+ select {
|
|
|
|
|
+ case plugCycle <- true:
|
|
|
|
|
+ case <-done:
|
|
|
|
|
+ return nil
|
|
|
|
|
+ }
|
|
|
|
|
+ waitingForPlug = false
|
|
|
|
|
+ }
|
|
|
|
|
+ case <-done:
|
|
|
|
|
+ return nil
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- return nil
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//export RTU_IsInetAvailable
|
|
//export RTU_IsInetAvailable
|