mirror of
https://github.com/safing/portbase
synced 2025-09-01 10:09:50 +00:00
Improve exported module and subsystem states
This commit is contained in:
parent
ddba5b44b9
commit
4dcec099e6
2 changed files with 11 additions and 12 deletions
|
@ -30,11 +30,16 @@ func (m *Module) SetEnabled(enable bool) (changed bool) {
|
|||
return m.Disable()
|
||||
}
|
||||
|
||||
// Enabled returns wether or not the module is currently enabled.
|
||||
// Enabled returns whether or not the module is currently enabled.
|
||||
func (m *Module) Enabled() bool {
|
||||
return m.enabled.IsSet()
|
||||
}
|
||||
|
||||
// EnabledAsDependency returns whether or not the module is currently enabled as a dependency.
|
||||
func (m *Module) EnabledAsDependency() bool {
|
||||
return m.enabledAsDependency.IsSet()
|
||||
}
|
||||
|
||||
// EnableModuleManagement enables the module management functionality within modules. The supplied notify function will be called whenever the status of a module changes. The affected module will be in the parameter. You will need to manually enable modules, else nothing will start.
|
||||
func EnableModuleManagement(changeNotifyFn func(*Module)) {
|
||||
if moduleMgmtEnabled.SetToIf(false, true) {
|
||||
|
|
|
@ -63,7 +63,7 @@ func statusFromModule(module *modules.Module) *ModuleStatus {
|
|||
status := &ModuleStatus{
|
||||
Name: module.Name,
|
||||
module: module,
|
||||
Enabled: module.Enabled(),
|
||||
Enabled: module.Enabled() || module.EnabledAsDependency(),
|
||||
Status: module.Status(),
|
||||
}
|
||||
status.FailureStatus, status.FailureID, status.FailureMsg = module.FailureStatus()
|
||||
|
@ -73,7 +73,7 @@ func statusFromModule(module *modules.Module) *ModuleStatus {
|
|||
|
||||
func compareAndUpdateStatus(module *modules.Module, status *ModuleStatus) (changed bool) {
|
||||
// check if enabled
|
||||
enabled := module.Enabled()
|
||||
enabled := module.Enabled() || module.EnabledAsDependency()
|
||||
if status.Enabled != enabled {
|
||||
status.Enabled = enabled
|
||||
changed = true
|
||||
|
@ -101,16 +101,10 @@ func compareAndUpdateStatus(module *modules.Module, status *ModuleStatus) (chang
|
|||
|
||||
func (sub *Subsystem) makeSummary() {
|
||||
// find worst failing module
|
||||
worstFailing := &ModuleStatus{}
|
||||
sub.FailureStatus = 0
|
||||
for _, depStatus := range sub.Modules {
|
||||
if depStatus.FailureStatus > worstFailing.FailureStatus {
|
||||
worstFailing = depStatus
|
||||
if depStatus.FailureStatus > sub.FailureStatus {
|
||||
sub.FailureStatus = depStatus.FailureStatus
|
||||
}
|
||||
}
|
||||
|
||||
if worstFailing != nil {
|
||||
sub.FailureStatus = worstFailing.FailureStatus
|
||||
} else {
|
||||
sub.FailureStatus = 0
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue