Skip to content

Commit

Permalink
Synchronize and cleanup maps appropriately
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelroquetto committed Oct 12, 2024
1 parent 24e1143 commit 979b73f
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pkg/internal/ebpf/tracer_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"log/slog"
"os"
"reflect"
"runtime"
"strings"
"sync"

Expand All @@ -27,6 +28,7 @@ const PinInternal = ebpf.PinType(100)
var loadMux sync.Mutex

var internalMaps = make(map[string]*ebpf.Map)
var internalMapsMux sync.Mutex

func ptlog() *slog.Logger { return slog.With("component", "ebpf.ProcessTracer") }

Expand All @@ -40,6 +42,9 @@ type instrumenter struct {
func resolveInternalMaps(spec *ebpf.CollectionSpec) (*ebpf.CollectionOptions, error) {
collOpts := ebpf.CollectionOptions{MapReplacements: map[string]*ebpf.Map{}}

internalMapsMux.Lock()
defer internalMapsMux.Unlock()

for k, v := range spec.Maps {
if v.Pinning != PinInternal {
continue
Expand All @@ -58,6 +63,7 @@ func resolveInternalMaps(spec *ebpf.CollectionSpec) (*ebpf.CollectionOptions, er
}

internalMaps[k] = internalMap
runtime.SetFinalizer(internalMap, (*ebpf.Map).Close)
}

collOpts.MapReplacements[k] = internalMap
Expand Down

0 comments on commit 979b73f

Please sign in to comment.