Skip to content

Commit

Permalink
fix: fix hengyoush#159 stuck when load bpf failed
Browse files Browse the repository at this point in the history
  • Loading branch information
hengyoush committed Dec 16, 2024
1 parent 7d53005 commit 91d60d5
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
8 changes: 8 additions & 0 deletions agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ func SetupAgent(options ac.AgentOptions) {
if bf != nil {
bf.Close()
}
_bf.Err = err
options.LoadPorgressChannel <- "❌ Kyanos start failed"
options.LoadPorgressChannel <- "quit"
return
}
_bf.Links = bf.Links
Expand Down Expand Up @@ -118,10 +121,15 @@ func SetupAgent(options ac.AgentOptions) {
}()
if !options.WatchOptions.DebugOutput {
loader_render.Start(ctx, options)
common.SetLogToStdout()
} else {
wg.Wait()
common.AgentLog.Info("Waiting for events..")
}
if _bf.Err != nil {
common.AgentLog.Error("Failed to load BPF: ", _bf.Err)
return
}

stop := false
go func() {
Expand Down
18 changes: 5 additions & 13 deletions bpf/loader/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,14 @@ import (
type BPF struct {
Links *list.List // close
Objs *bpf.AgentObjects // close
Err error
}

func (b *BPF) Close() {
b.Objs.Close()
if b.Objs != nil {
b.Objs.Close()
}

if b.Links != nil {
for e := b.Links.Front(); e != nil; e = e.Next() {
if e.Value == nil {
Expand Down Expand Up @@ -112,20 +116,8 @@ func LoadBPF(options *ac.AgentOptions) (*BPF, error) {
}
options.LoadPorgressChannel <- "🍓 Setup traffic filters"

// var links *list.List
// if options.LoadBpfProgramFunction != nil {
// links = options.LoadBpfProgramFunction()
// } else {
// links = attachBpfProgs(options.IfName, options.Kv, &options)
// }

// if !options.DisableOpensslUprobe {
// attachOpenSslUprobes(links, options, options.Kv, objs)
// }
// attachNfFunctions(links)
bpf.PullProcessExitEvents(options.Ctx, []chan *bpf.AgentProcessExitEvent{initProcExitEventChannel(options.Ctx)})

// bf.links = links
return bf, nil
}

Expand Down
9 changes: 9 additions & 0 deletions common/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package common

import (
"io"
"os"
"time"

"github.com/jefurry/logrus"
Expand Down Expand Up @@ -58,3 +59,11 @@ func SetLogToFile() {
}
}
}

func SetLogToStdout() {
SetLogToFileFlag = false
for _, l := range Loggers {
// 设置为stdout
l.SetOut(os.Stdout)
}
}

0 comments on commit 91d60d5

Please sign in to comment.