mirror of
https://github.com/safing/portbase
synced 2025-09-01 18:19:57 +00:00
Fix failure updating during module shutdown
This commit is contained in:
parent
9a76cf153d
commit
3597a6900e
1 changed files with 27 additions and 28 deletions
|
@ -65,16 +65,16 @@ func (m *Module) OnlineSoon() bool {
|
||||||
|
|
||||||
// Status returns the current module status.
|
// Status returns the current module status.
|
||||||
func (m *Module) Status() uint8 {
|
func (m *Module) Status() uint8 {
|
||||||
m.RLock()
|
m.Lock()
|
||||||
defer m.RUnlock()
|
defer m.Unlock()
|
||||||
|
|
||||||
return m.status
|
return m.status
|
||||||
}
|
}
|
||||||
|
|
||||||
// FailureStatus returns the current failure status, ID and message.
|
// FailureStatus returns the current failure status, ID and message.
|
||||||
func (m *Module) FailureStatus() (failureStatus uint8, failureID, failureMsg string) {
|
func (m *Module) FailureStatus() (failureStatus uint8, failureID, failureMsg string) {
|
||||||
m.RLock()
|
m.Lock()
|
||||||
defer m.RUnlock()
|
defer m.Unlock()
|
||||||
|
|
||||||
return m.failureStatus, m.failureID, m.failureMsg
|
return m.failureStatus, m.failureID, m.failureMsg
|
||||||
}
|
}
|
||||||
|
@ -88,10 +88,7 @@ func (m *Module) FailureStatus() (failureStatus uint8, failureID, failureMsg str
|
||||||
// Hint(), Warning() or Error() with the same ID as the existing one will be
|
// Hint(), Warning() or Error() with the same ID as the existing one will be
|
||||||
// ignored.
|
// ignored.
|
||||||
func (m *Module) Hint(id, title, msg string) {
|
func (m *Module) Hint(id, title, msg string) {
|
||||||
m.Lock()
|
m.setFailure(FailureHint, id, title, msg, true)
|
||||||
defer m.Unlock()
|
|
||||||
|
|
||||||
m.setFailure(FailureHint, id, title, msg)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Warning sets failure status to warning. The supplied failureID is for
|
// Warning sets failure status to warning. The supplied failureID is for
|
||||||
|
@ -101,10 +98,7 @@ func (m *Module) Hint(id, title, msg string) {
|
||||||
// Hint(), Warning() or Error() with the same ID as the existing one will be
|
// Hint(), Warning() or Error() with the same ID as the existing one will be
|
||||||
// ignored.
|
// ignored.
|
||||||
func (m *Module) Warning(id, title, msg string) {
|
func (m *Module) Warning(id, title, msg string) {
|
||||||
m.Lock()
|
m.setFailure(FailureWarning, id, title, msg, true)
|
||||||
defer m.Unlock()
|
|
||||||
|
|
||||||
m.setFailure(FailureWarning, id, title, msg)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Error sets failure status to error. The supplied failureID is for improved
|
// Error sets failure status to error. The supplied failureID is for improved
|
||||||
|
@ -113,26 +107,31 @@ func (m *Module) Warning(id, title, msg string) {
|
||||||
// Hint(), Warning() or Error() with the same ID as the existing one will be
|
// Hint(), Warning() or Error() with the same ID as the existing one will be
|
||||||
// ignored.
|
// ignored.
|
||||||
func (m *Module) Error(id, title, msg string) {
|
func (m *Module) Error(id, title, msg string) {
|
||||||
m.Lock()
|
m.setFailure(FailureError, id, title, msg, true)
|
||||||
defer m.Unlock()
|
|
||||||
|
|
||||||
m.setFailure(FailureError, id, title, msg)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Module) setFailure(status uint8, id, title, msg string) {
|
func (m *Module) setFailure(status uint8, id, title, msg string, lockModule bool) {
|
||||||
// Ignore calls with the same ID.
|
var resolveFailureID string
|
||||||
if id == m.failureID {
|
func() {
|
||||||
return
|
if lockModule {
|
||||||
}
|
m.Lock()
|
||||||
|
defer m.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
// Copy data for failure status update worker.
|
// Ignore calls with the same ID.
|
||||||
resolveFailureID := m.failureID
|
if id == m.failureID {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Set new failure status.
|
// Copy data for failure status update worker.
|
||||||
m.failureStatus = status
|
resolveFailureID = m.failureID
|
||||||
m.failureID = id
|
|
||||||
m.failureTitle = title
|
// Set new failure status.
|
||||||
m.failureMsg = msg
|
m.failureStatus = status
|
||||||
|
m.failureID = id
|
||||||
|
m.failureTitle = title
|
||||||
|
m.failureMsg = msg
|
||||||
|
}()
|
||||||
|
|
||||||
// Notify of module change.
|
// Notify of module change.
|
||||||
m.notifyOfChange()
|
m.notifyOfChange()
|
||||||
|
|
Loading…
Add table
Reference in a new issue