From 12a6c519a850b84243bb8340f60847b3d2876649 Mon Sep 17 00:00:00 2001 From: gVisor bot Date: Mon, 1 Aug 2022 18:06:09 +0800 Subject: [PATCH] revert 9be70f67ca802d05372b239626048791b3978c0a --- component/process/process_linux.go | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) 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)