This commit is contained in:
gVisor bot 2022-08-01 18:06:09 +08:00
parent 93dbc0cc7f
commit 12a6c519a8

View file

@ -8,6 +8,7 @@ import (
"net/netip" "net/netip"
"os" "os"
"path" "path"
"runtime"
"strings" "strings"
"syscall" "syscall"
"unicode" "unicode"
@ -196,16 +197,39 @@ func resolveProcessNameByProcSearch(inode, uid int32) (string, error) {
if err != nil { if err != nil {
continue continue
} }
if runtime.GOOS == "android" {
if bytes.Equal(buffer[:n], socket) {
cmdline, err := os.ReadFile(path.Join(processPath, "cmdline"))
if err != nil {
return "", err
}
return splitCmdline(cmdline), nil
}
} else {
if bytes.Equal(buffer[:n], socket) { if bytes.Equal(buffer[:n], socket) {
return os.Readlink(path.Join(processPath, "exe")) return os.Readlink(path.Join(processPath, "exe"))
} }
} }
} }
}
return "", fmt.Errorf("process of uid(%d),inode(%d) not found", uid, inode) 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 { func isPid(s string) bool {
return strings.IndexFunc(s, func(r rune) bool { return strings.IndexFunc(s, func(r rune) bool {
return !unicode.IsDigit(r) return !unicode.IsDigit(r)