Skip to content

Commit

Permalink
fix: event receiver loop from perf buffer
Browse files Browse the repository at this point in the history
Signed-off-by: Alessio Greggi <ale_grey_91@hotmail.it>
  • Loading branch information
alegrey91 committed Apr 21, 2024
1 parent c4c5cf5 commit 0e0f774
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion ebpf/ebpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ int trace_syscall(struct trace_event_raw_sys_enter* args) {

tc = bpf_map_lookup_elem(&tracing_status, &key_map_trace);
if (!tc) {
bpf_printk("error getting tracing status\n");
bpf_printk("error getting tracing status");
return 1;
}
if (tc->status != 1) {
Expand Down
28 changes: 18 additions & 10 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ type event struct {
//go:embed output/*
var eBPFObject embed.FS
var version = "test"
var uprobeEnterFunc = "enter_function"
var uprobeExitFunc = "exit_function"
var tracepointCategory = "raw_syscalls"
var tracepointName = "sys_enter"

Expand Down Expand Up @@ -89,15 +91,15 @@ func main() {
}

bpfModule.BPFLoadObject()
enterFuncProbe, err := bpfModule.GetProgram("enter_function")
enterFuncProbe, err := bpfModule.GetProgram(uprobeEnterFunc)
if err != nil {
fmt.Printf("error loading program 'enter_function': %v\n", err)
fmt.Printf("error loading program '%s': %v\n", uprobeEnterFunc, err)
os.Exit(-1)
}

exitFuncProbe, err := bpfModule.GetProgram("exit_function")
exitFuncProbe, err := bpfModule.GetProgram(uprobeExitFunc)
if err != nil {
fmt.Printf("error loading program 'exit_function': %v\n", err)
fmt.Printf("error loading program '%s': %v\n", uprobeExitFunc, err)
os.Exit(-1)
}

Expand Down Expand Up @@ -186,13 +188,19 @@ func main() {

var syscalls []uint32
go func() {
for data := range eventsChannel {
var e event
if err := binary.Read(bytes.NewBuffer(data), binary.LittleEndian, &e); err != nil {
fmt.Printf("failed to decode received data %q: %s\n", data, err)
return
//for data := range eventsChannel {
for {
select {
case data := <-eventsChannel:
var e event
if err := binary.Read(bytes.NewBuffer(data), binary.LittleEndian, &e); err != nil {
fmt.Printf("failed to decode received data %q: %s\n", data, err)
return
}
syscalls = append(syscalls, e.SyscallID)
case lost := <-lostChannel:
fmt.Printf("lost %d data", lost)
}
syscalls = append(syscalls, e.SyscallID)
}
}()

Expand Down

0 comments on commit 0e0f774

Please sign in to comment.