Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sensors: modify unload hooks and remove GetConfig and SetConfig #1385

Merged
merged 7 commits into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions pkg/sensors/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ func (s *Sensor) Unload() error {
return fmt.Errorf("unload of sensor %s failed: sensor not loaded", s.Name)
}

if s.UnloadHook != nil {
if err := s.UnloadHook(); err != nil {
logger.GetLogger().Warnf("Sensor %s unload hook failed: %s", s.Name, err)
if s.PreUnloadHook != nil {
if err := s.PreUnloadHook(); err != nil {
logger.GetLogger().Warnf("Sensor %s pre unload hook failed: %s", s.Name, err)
}
}

Expand All @@ -139,6 +139,13 @@ func (s *Sensor) Unload() error {
}

s.Loaded = false

if s.PostUnloadHook != nil {
if err := s.PostUnloadHook(); err != nil {
logger.GetLogger().Warnf("Sensor %s post unload hook failed: %s", s.Name, err)
mtardy marked this conversation as resolved.
Show resolved Hide resolved
}
}

return nil
}

Expand Down
8 changes: 6 additions & 2 deletions pkg/sensors/sensors.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,14 @@ type Sensor struct {
Loaded bool
// Ops contains an implementation to perform on this sensor.
Ops Operations
// UnloadHook can optionally contain a pointer to a function to be
// PreUnloadHook can optionally contain a pointer to a function to be
// called during sensor unloading, prior to the programs and maps being
// unloaded.
UnloadHook SensorUnloadHook
PreUnloadHook SensorUnloadHook
// PostUnloadHook can optionally contain a pointer to a function to be
// called during sensor unloading, after the programs and maps being
// unloaded.
PostUnloadHook SensorUnloadHook
}

// Operations is the interface to the underlying sensor implementations.
Expand Down