Skip to content

Commit 0661791

Browse files
committed
change BPF config detect logic.
Signed-off-by: CFC4N <cfc4n.cs@gmail.com>
1 parent c425dea commit 0661791

3 files changed

Lines changed: 14 additions & 13 deletions

File tree

cli/cmd/root.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ package cmd
66

77
import (
88
"ecapture/cli/cobrautl"
9+
"ecapture/pkg/util/ebpf"
10+
"log"
911
"os"
1012

1113
"github.com/spf13/cobra"
@@ -57,6 +59,15 @@ func Execute() {
5759
rootCmd.Version = GitVersion
5860
rootCmd.SetVersionTemplate(`{{with .Name}}{{printf "%s " .}}{{end}}{{printf "version:\t%s" .Version}}
5961
`)
62+
enable, e := ebpf.IsEnableBPF()
63+
if e != nil {
64+
log.Fatalf("Kernel config read failed, error:%v", e)
65+
}
66+
67+
if !enable {
68+
log.Fatalf("Kernel not support, error:%v", e)
69+
}
70+
6071
err := rootCmd.Execute()
6172
if err != nil {
6273
os.Exit(1)

main.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,6 @@ func main() {
2727
log.Fatalf("Linux Kernel version %v is not supported. Need > 4.18 .", kv)
2828
}
2929

30-
enable, e := ebpf.IsEnableBPF()
31-
if e != nil {
32-
log.Fatalf("Kernel config read failed, error:%v", e)
33-
}
34-
35-
if !enable {
36-
log.Fatalf("Kernel not support, error:%v", e)
37-
}
38-
3930
// changed by go build '-ldflags X'
4031
if enableCORE == "true" {
4132
// BTF支持情况检测
@@ -49,7 +40,5 @@ func main() {
4940
}
5041
}
5142

52-
// TODO check UPROBE
53-
5443
cli.Start()
5544
}

pkg/util/ebpf/bpf.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ func IsEnableBTF() (bool, error) {
114114
return true, nil
115115
}
116116

117+
// check BPF CONFIG
117118
func IsEnableBPF() (bool, error) {
118119
var e error
119120
var KernelConfig = make(map[string]string)
@@ -127,13 +128,13 @@ func IsEnableBPF() (bool, error) {
127128
bc, found := KernelConfig[item]
128129
if !found {
129130
// 没有这个配置项
130-
return false, fmt.Errorf("Notfound config item:%s", item)
131+
return false, fmt.Errorf("Config not found, item:%s.", item)
131132
}
132133

133134
//如果有,在判断配置项的值
134135
if bc != "y" {
135136
// 没有开启
136-
return false, fmt.Errorf("config item:%s not enable.", item)
137+
return false, fmt.Errorf("Config disabled, item :%s.", item)
137138
}
138139
}
139140

0 commit comments

Comments
 (0)