From 6de35fac4581e9cc6e128a5a876135c853537aac Mon Sep 17 00:00:00 2001 From: CFC4N Date: Tue, 5 Jul 2022 20:50:35 +0800 Subject: [PATCH 1/2] pkg : fix Kernel config read failed, error:Config not found #117 Signed-off-by: CFC4N --- pkg/util/ebpf/bpf_linux.go | 16 ++++++++++++--- pkg/util/ebpf/bpf_test.go | 40 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 pkg/util/ebpf/bpf_test.go diff --git a/pkg/util/ebpf/bpf_linux.go b/pkg/util/ebpf/bpf_linux.go index a8dad21c7..3576e97cd 100644 --- a/pkg/util/ebpf/bpf_linux.go +++ b/pkg/util/ebpf/bpf_linux.go @@ -7,6 +7,7 @@ import ( "bufio" "fmt" "os" + "strings" ) const ( @@ -37,24 +38,33 @@ var ( func GetSystemConfig() (map[string]string, error) { var KernelConfig = make(map[string]string) - + var found bool i, e := getOSUnamer() if e != nil { return KernelConfig, e } for _, system_config_path := range configPaths { - bootConf := fmt.Sprintf(system_config_path, i.Release) + var bootConf = system_config_path + if strings.Index(system_config_path, "%s") != -1 { + bootConf = fmt.Sprintf(system_config_path, i.Release) + } + KernelConfig, e = getLinuxConfig(bootConf) if e != nil { + // 没有找到配置文件,继续找下一个 continue } if len(KernelConfig) > 0 { + found = true break } } + if !found { + return nil, fmt.Errorf("KernelConfig not found.") + } return KernelConfig, nil } @@ -69,7 +79,7 @@ func getLinuxConfig(filename string) (map[string]string, error) { defer f.Close() s := bufio.NewScanner(f) - if err := parse(s, KernelConfig); err != nil { + if err = parse(s, KernelConfig); err != nil { return KernelConfig, err } return KernelConfig, nil diff --git a/pkg/util/ebpf/bpf_test.go b/pkg/util/ebpf/bpf_test.go new file mode 100644 index 000000000..9d0864c31 --- /dev/null +++ b/pkg/util/ebpf/bpf_test.go @@ -0,0 +1,40 @@ +package ebpf + +import ( + "testing" +) + +func TestBpfConfig(t *testing.T) { + configPaths = []string{ + "/xxxxx/proc/config.gz", // android + } + m, e := GetSystemConfig() + if e != nil { + // 正常情况 是没有找到配置文件 + t.Logf("GetSystemConfig error:%s", e.Error()) + } + + configPaths = []string{ + "/proc/config.gz", // android + "/boot/config", // linux + "/boot/config-%s", // linux + } + m, e = GetSystemConfig() + if e != nil { + t.Fatalf("GetSystemConfig error:%s", e.Error()) + } + for _, item := range configCheckItems { + bc, found := m[item] + if !found { + // 没有这个配置项 + t.Logf("Config not found, item:%s.", item) + } + + //如果有,在判断配置项的值 + if bc != "y" { + // 没有开启 + t.Logf("Config disabled, item :%s.", item) + } + } + t.Logf("GetSystemConfig success") +} From 5633f2e5f3a853628d8919f123dd7d95c40f8a4f Mon Sep 17 00:00:00 2001 From: CFC4N Date: Tue, 5 Jul 2022 21:04:11 +0800 Subject: [PATCH 2/2] workflow: disable go test on qemu Signed-off-by: CFC4N --- .github/workflows/go-c-cpp.yml | 1 - .github/workflows/release.yml | 1 - 2 files changed, 2 deletions(-) diff --git a/.github/workflows/go-c-cpp.yml b/.github/workflows/go-c-cpp.yml index aa19524c1..37e951f7d 100644 --- a/.github/workflows/go-c-cpp.yml +++ b/.github/workflows/go-c-cpp.yml @@ -246,7 +246,6 @@ jobs: tar -czf ${OUT_ARCHIVE} ${TAR_DIR} cp ${OUT_ARCHIVE} "/artifacts/" echo "-------------------end: Create ecapture.tar.gz of Android GKI -------------------" - go test -v ./... echo "Produced artifact at /artifacts/${artifact_name}" - name: Show the artifact diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ffab8ffee..c8b8b61e9 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -195,7 +195,6 @@ jobs: tar -czf ${OUT_ARCHIVE} ${TAR_DIR} cp ${OUT_ARCHIVE} "/artifacts/" echo "-------------------end: Create ecapture.tar.gz of Android kernel 4.18+ -------------------" - go test -v ./... echo "Produced artifact at /artifacts/${artifact_name}" - name: Upload artifacts