From b9b948858bbc7ccf3146e53f9df43629c3eac7a8 Mon Sep 17 00:00:00 2001 From: Jiri Olsa Date: Sun, 7 Jan 2024 13:52:32 +0000 Subject: [PATCH] tetragon: Add sensor PostLoadHook hook Adding sensor PostLoadHook hook, it will be used in following changes in kprobe sensor to kill the stats timer. Signed-off-by: Jiri Olsa --- pkg/sensors/load.go | 5 +++++ pkg/sensors/sensors.go | 2 ++ 2 files changed, 7 insertions(+) diff --git a/pkg/sensors/load.go b/pkg/sensors/load.go index ee931ae76d4..d61b6834892 100644 --- a/pkg/sensors/load.go +++ b/pkg/sensors/load.go @@ -114,6 +114,11 @@ func (s *Sensor) Load(bpfDir string) error { p.LoadState.RefInc() l.WithField("prog", p.Name).WithField("label", p.Label).Debugf("BPF prog was loaded") } + if s.PostLoadHook != nil { + if err := s.PostLoadHook(); err != nil { + logger.GetLogger().WithError(err).WithField("sensor", s.Name).Warn("Post load hook failed") + } + } l.WithField("sensor", s.Name).Infof("Loaded BPF maps and events for sensor successfully") s.Loaded = true return nil diff --git a/pkg/sensors/sensors.go b/pkg/sensors/sensors.go index ba6dd352f7b..38ce74f7aa0 100644 --- a/pkg/sensors/sensors.go +++ b/pkg/sensors/sensors.go @@ -44,6 +44,8 @@ type Sensor struct { Loaded bool // Destroyed indicates whether the sensor had been destroyed. Destroyed bool + // PostLoadHook hook + PostLoadHook SensorHook // PreUnloadHook can optionally contain a pointer to a function to be // called during sensor unloading, prior to the programs and maps being // unloaded.