From 6de9af62cc16332ca322929882e67cc027a82d18 Mon Sep 17 00:00:00 2001 From: 兔子 Date: Thu, 26 Nov 2020 16:14:12 +0800 Subject: [PATCH] fix bug while use common user --- process_unix.go | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/process_unix.go b/process_unix.go index 967e852..985cc05 100644 --- a/process_unix.go +++ b/process_unix.go @@ -37,7 +37,10 @@ func FindProcess(compare func(Process) bool) (datas []Process, err error) { } for _, v := range paths { if v.IsDir() && Exists("/proc/"+v.Name()+"/comm") { - name, _ = readAsString("/proc/" + v.Name() + "/comm") + name, err = readAsString("/proc/" + v.Name() + "/comm") + if err != nil { + continue + } var tmp Process tmp.LocalPath, err = os.Readlink("/proc/" + v.Name() + "/exe") tmp.Path = tmp.LocalPath @@ -124,7 +127,13 @@ func FindProcessByPid(pid int64) (datas Process, err error) { return } name, err = readAsString("/proc/" + fmt.Sprint(pid) + "/comm") + if err != nil { + return err + } main, err = readAsString("/proc/" + fmt.Sprint(pid) + "/status") + if err != nil { + return err + } data := splitBy(main, ":") datas.Name = strings.TrimSpace(name) datas.Pid, _ = strconv.ParseInt(data["Pid"], 10, 64) @@ -167,15 +176,9 @@ func FindProcessByPid(pid int64) (datas Process, err error) { } datas.LocalPath, err = os.Readlink("/proc/" + fmt.Sprint(pid) + "/exe") - if err != nil { - return - } datas.Path = datas.LocalPath datas.LocalPath = filepath.Dir(datas.LocalPath) datas.ExecPath, err = os.Readlink("/proc/" + fmt.Sprint(pid) + "/cwd") - if err != nil { - return - } main, err = readAsString("/proc/" + fmt.Sprint(pid) + "/stat") if err != nil { return