diff --git a/component/process/process_linux.go b/component/process/process_linux.go index d8a00eb5..b5ae68ef 100644 --- a/component/process/process_linux.go +++ b/component/process/process_linux.go @@ -8,6 +8,7 @@ import ( "net/netip" "os" "path" + "runtime" "strings" "syscall" "unicode" @@ -196,9 +197,19 @@ func resolveProcessNameByProcSearch(inode, uid int32) (string, error) { if err != nil { continue } + if runtime.GOOS == "android" { + if bytes.Equal(buffer[:n], socket) { + cmdline, err := os.ReadFile(path.Join(processPath, "cmdline")) + if err != nil { + return "", err + } - if bytes.Equal(buffer[:n], socket) { - return os.Readlink(path.Join(processPath, "exe")) + return splitCmdline(cmdline), nil + } + } else { + if bytes.Equal(buffer[:n], socket) { + return os.Readlink(path.Join(processPath, "exe")) + } } } } @@ -206,6 +217,19 @@ func resolveProcessNameByProcSearch(inode, uid int32) (string, error) { return "", fmt.Errorf("process of uid(%d),inode(%d) not found", uid, inode) } +func splitCmdline(cmdline []byte) string { + cmdline = bytes.Trim(cmdline, " ") + + idx := bytes.IndexFunc(cmdline, func(r rune) bool { + return unicode.IsControl(r) || unicode.IsSpace(r) + }) + + if idx == -1 { + return filepath.Base(string(cmdline)) + } + return filepath.Base(string(cmdline[:idx])) +} + func isPid(s string) bool { return strings.IndexFunc(s, func(r rune) bool { return !unicode.IsDigit(r)