Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkg : fix Kernel config read failed, error:Config not found #117 #123

Merged
merged 2 commits into from
Jul 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/go-c-cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 13 additions & 3 deletions pkg/util/ebpf/bpf_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"bufio"
"fmt"
"os"
"strings"
)

const (
Expand Down Expand Up @@ -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
}

Expand All @@ -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
Expand Down
40 changes: 40 additions & 0 deletions pkg/util/ebpf/bpf_test.go
Original file line number Diff line number Diff line change
@@ -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")
}