Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
Signed-off-by: Jiri Olsa <[email protected]>
  • Loading branch information
olsajiri committed Aug 17, 2024
1 parent 84c722b commit 1359e34
Show file tree
Hide file tree
Showing 11 changed files with 17 additions and 33 deletions.
2 changes: 0 additions & 2 deletions pkg/sensors/base/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ func GetInitialSensor() *sensors.Sensor {
sensorInit.Do(func() {
setupPrograms()
sensor.Progs = GetDefaultPrograms(option.CgroupRateEnabled())
sensor.Maps = GetDefaultMaps(option.CgroupRateEnabled())
})
return &sensor
}
Expand All @@ -175,7 +174,6 @@ func GetInitialSensorTest() *sensors.Sensor {
sensorTestInit.Do(func() {
setupPrograms()
sensorTest.Progs = GetDefaultPrograms(true)
sensorTest.Maps = GetDefaultMaps(true)
})
return &sensorTest
}
Expand Down
12 changes: 4 additions & 8 deletions pkg/sensors/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ func (s *Sensor) Load(bpfDir string) error {

// Add the *loaded* programs and maps, so they can be unloaded later
progsAdd(s.Progs)
AllMaps = append(AllMaps, s.Maps...)

l.WithField("sensor", s.Name).Infof("Loaded BPF maps and events for sensor successfully")
s.Loaded = true
Expand Down Expand Up @@ -196,27 +195,24 @@ func (s *Sensor) FindPrograms() error {
if err := s.findProgram(p); err != nil {
return err
}
}
for _, m := range s.Maps {
if err := s.findProgram(m.Prog); err != nil {
return err
for _, m := range p.PinMap {
if err := s.findProgram(m.Prog); err != nil {
return err
}
}
}
return nil
}

func mergeSensors(sensors []*Sensor) *Sensor {
var progs []*program.Program
var maps []*program.Map

for _, s := range sensors {
progs = append(progs, s.Progs...)
maps = append(maps, s.Maps...)
}
return &Sensor{
Name: "__main__",
Progs: progs,
Maps: maps,
}
}

Expand Down
9 changes: 2 additions & 7 deletions pkg/sensors/sensors.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ type Sensor struct {
Name string
// Progs are all the BPF programs that exist on the filesystem.
Progs []*program.Program
// Maps are all the BPF Maps that the progs use.
Maps []*program.Map
// Loaded indicates whether the sensor has been Loaded.
Loaded bool
// Destroyed indicates whether the sensor had been destroyed.
Expand Down Expand Up @@ -84,19 +82,16 @@ type SensorHook func() error

func SensorCombine(name string, sensors ...*Sensor) *Sensor {
progs := []*program.Program{}
maps := []*program.Map{}
for _, s := range sensors {
progs = append(progs, s.Progs...)
maps = append(maps, s.Maps...)
}
return SensorBuilder(name, progs, maps)
return SensorBuilder(name, progs)
}

func SensorBuilder(name string, p []*program.Program, m []*program.Map) *Sensor {
func SensorBuilder(name string, p []*program.Program) *Sensor {
return &Sensor{
Name: name,
Progs: p,
Maps: m,
}
}

Expand Down
8 changes: 0 additions & 8 deletions pkg/sensors/test/cgroups.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,10 @@ func getCgroupPrograms() []*program.Program {
return progs
}

func getCgroupMaps() []*program.Map {
maps := []*program.Map{
GetCgroupsTrackingMap(),
}
return maps
}

// GetCgroupSensor returns the Cgroups base sensor
func GetCgroupSensor() *sensors.Sensor {
return &sensors.Sensor{
Name: "test-sensor-cgroups",
Progs: getCgroupPrograms(),
Maps: getCgroupMaps(),
}
}
3 changes: 1 addition & 2 deletions pkg/sensors/test/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ func GetTestSensor() *sensors.Sensor {
sensors.PathJoin(sensorName, "test_lseek_prog"),
"tracepoint",
)}
maps := []*program.Map{}
sensor := &sensors.Sensor{Name: sensorName, Progs: progs, Maps: maps}
sensor := &sensors.Sensor{Name: sensorName, Progs: progs}
return sensor
}
3 changes: 2 additions & 1 deletion pkg/sensors/tracing/enforcer.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,10 +326,11 @@ func (kp *enforcerPolicy) createEnforcerSensor(

logger.GetLogger().Infof("Added enforcer sensor '%s'", name)

fmt.Printf("KRAVA maps %d\n", len(maps))

return &sensors.Sensor{
Name: "__enforcer__",
Progs: progs,
Maps: maps,
PostUnloadHook: func() error {
if ok := kp.enforcerDel(name); !ok {
logger.GetLogger().Infof("Failed to clean up enforcer sensor '%s'", name)
Expand Down
3 changes: 2 additions & 1 deletion pkg/sensors/tracing/generickprobe.go
Original file line number Diff line number Diff line change
Expand Up @@ -658,10 +658,11 @@ func createGenericKprobeSensor(
return nil, err
}

fmt.Printf("KRAVA maps %d\n", len(maps))

return &sensors.Sensor{
Name: name,
Progs: progs,
Maps: maps,
DestroyHook: func() error {
var errs error
for _, id := range ids {
Expand Down
3 changes: 2 additions & 1 deletion pkg/sensors/tracing/genericlsm.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,10 +327,11 @@ func createGenericLsmSensor(
return nil, err
}

fmt.Printf("KRAVA maps %d\n", len(maps))

return &sensors.Sensor{
Name: name,
Progs: progs,
Maps: maps,
DestroyHook: func() error {
var errs error
for _, id := range ids {
Expand Down
3 changes: 2 additions & 1 deletion pkg/sensors/tracing/generictracepoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -509,10 +509,11 @@ func createGenericTracepointSensor(
maps = append(maps, selMatchBinariesMap)
}

fmt.Printf("KRAVA maps %d\n", len(maps))

return &sensors.Sensor{
Name: name,
Progs: progs,
Maps: maps,
}, nil
}

Expand Down
3 changes: 2 additions & 1 deletion pkg/sensors/tracing/genericuprobe.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,10 +287,11 @@ func createGenericUprobeSensor(
return nil, err
}

fmt.Printf("KRAVA maps %d\n", len(maps))

return &sensors.Sensor{
Name: name,
Progs: progs,
Maps: maps,
}, nil
}

Expand Down
1 change: 0 additions & 1 deletion pkg/sensors/tracing/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ func GetLoaderSensor() *sensors.Sensor {
return &sensors.Sensor{
Name: "__loader__",
Progs: []*program.Program{loader},
Maps: []*program.Map{idsMap},
}
}

Expand Down

0 comments on commit 1359e34

Please sign in to comment.