From 8ef09e3af851706b09d87c90535b9fe26e6dda83 Mon Sep 17 00:00:00 2001 From: gVisor bot Date: Sat, 5 Mar 2022 18:25:16 +0800 Subject: [PATCH] Fix: should split linux process name with space (#2008) --- component/process/process_linux.go | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/component/process/process_linux.go b/component/process/process_linux.go index be758a69..0ca42716 100644 --- a/component/process/process_linux.go +++ b/component/process/process_linux.go @@ -9,7 +9,9 @@ import ( "os" "path" "path/filepath" + "strings" "syscall" + "unicode" "unsafe" "github.com/Dreamacro/clash/common/pool" @@ -219,24 +221,15 @@ func resolveProcessNameByProcSearch(inode, uid int) (string, error) { } func splitCmdline(cmdline []byte) string { - indexOfEndOfString := len(cmdline) + idx := bytes.IndexFunc(cmdline, func(r rune) bool { + return unicode.IsControl(r) || unicode.IsSpace(r) + }) - for i, c := range cmdline { - if c == 0 { - indexOfEndOfString = i - break - } - } - - return filepath.Base(string(cmdline[:indexOfEndOfString])) + return filepath.Base(string(cmdline[:idx])) } func isPid(s string) bool { - for _, s := range s { - if s < '0' || s > '9' { - return false - } - } - - return true + return strings.IndexFunc(s, func(r rune) bool { + return !unicode.IsDigit(r) + }) == -1 }