Skip to content

Commit

Permalink
try to avoid exec events were handled after packet events
Browse files Browse the repository at this point in the history
  • Loading branch information
mozillazg committed May 5, 2024
1 parent ee93014 commit 638d0c4
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion internal/consumer/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package consumer

import (
"context"
"log"
"sync"

"github.com/mozillazg/ptcpdump/bpf"
"github.com/mozillazg/ptcpdump/internal/event"
"github.com/mozillazg/ptcpdump/internal/metadata"
"log"
)

type ExecEventConsumer struct {
Expand All @@ -19,6 +21,18 @@ func NewExecEventConsumer(pcache *metadata.ProcessCache) *ExecEventConsumer {
}

func (c *ExecEventConsumer) Start(ctx context.Context, ch <-chan bpf.BpfExecEventT) {
wg := sync.WaitGroup{}
for i := 0; i < 5; i++ {
wg.Add(1)
go func() {
defer wg.Done()
c.worker(ctx, ch)
}()
}
wg.Wait()
}

func (c *ExecEventConsumer) worker(ctx context.Context, ch <-chan bpf.BpfExecEventT) {
for {
select {
case <-ctx.Done():
Expand Down

0 comments on commit 638d0c4

Please sign in to comment.