Skip to content

Commit

Permalink
Add locking around fanotify mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
bobrik committed Sep 13, 2023
1 parent 73575ef commit f54ad68
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions cgroup/fanotify.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"io"
"log"
"os"
"sync"
"syscall"

"github.com/cloudflare/ebpf_exporter/v2/util"
Expand All @@ -19,6 +20,7 @@ type fanotifyMonitor struct {
fanotify io.Reader
mount *os.File
mapping map[int]string
lock sync.RWMutex
byteOrder binary.ByteOrder
}

Expand All @@ -45,6 +47,7 @@ func newFanotifyMonitor(path string) (*fanotifyMonitor, error) {
fanotify: fanotify,
mount: mount,
mapping: mapping,
lock: sync.RWMutex{},
byteOrder: byteOrder,
}

Expand Down Expand Up @@ -132,7 +135,9 @@ func (m *fanotifyMonitor) handleFanotify(_ *unix.FanotifyEventMetadata, buf []by
return nil
}

m.lock.Lock()
m.mapping[inode] = path
m.lock.Unlock()

return nil
}
Expand Down Expand Up @@ -175,6 +180,8 @@ func (m *fanotifyMonitor) readFanotifyFileHandle(reader io.Reader) (unix.FileHan
}

func (m *fanotifyMonitor) Resolve(id int) string {
m.lock.RLock()
defer m.lock.RUnlock()
return m.mapping[id]
}

Expand Down

0 comments on commit f54ad68

Please sign in to comment.