From f43138a3ffd339db949877aa2799834680a349ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Wed, 19 May 2021 22:29:21 +0300 Subject: [PATCH] [process][solaris] improve Exe portability Resolving from path/a.out seems more portable than from execname. --- process/process_solaris.go | 16 +++++++++++++++- v3/process/process_solaris.go | 16 +++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/process/process_solaris.go b/process/process_solaris.go index b1a6e24..eb6af5a 100644 --- a/process/process_solaris.go +++ b/process/process_solaris.go @@ -66,7 +66,11 @@ func (p *Process) TgidWithContext(ctx context.Context) (int32, error) { } func (p *Process) ExeWithContext(ctx context.Context) (string, error) { - return p.fillFromExecnameWithContext(ctx) + exe, err := p.fillFromPathAOutWithContext(ctx) + if os.IsNotExist(err) { + exe, err = p.fillFromExecnameWithContext(ctx) + } + return exe, err } func (p *Process) CmdlineWithContext(ctx context.Context) (string, error) { @@ -220,6 +224,16 @@ func (p *Process) fillFromPathCwdWithContext(ctx context.Context) (string, error return cwd, nil } +func (p *Process) fillFromPathAOutWithContext(ctx context.Context) (string, error) { + pid := p.Pid + cwdPath := common.HostProc(strconv.Itoa(int(pid)), "path", "a.out") + exe, err := os.Readlink(cwdPath) + if err != nil { + return "", err + } + return exe, nil +} + func (p *Process) fillFromExecnameWithContext(ctx context.Context) (string, error) { pid := p.Pid execNamePath := common.HostProc(strconv.Itoa(int(pid)), "execname") diff --git a/v3/process/process_solaris.go b/v3/process/process_solaris.go index 4ca2b1d..38150e7 100644 --- a/v3/process/process_solaris.go +++ b/v3/process/process_solaris.go @@ -66,7 +66,11 @@ func (p *Process) TgidWithContext(ctx context.Context) (int32, error) { } func (p *Process) ExeWithContext(ctx context.Context) (string, error) { - return p.fillFromExecnameWithContext(ctx) + exe, err := p.fillFromPathAOutWithContext(ctx) + if os.IsNotExist(err) { + exe, err = p.fillFromExecnameWithContext(ctx) + } + return exe, err } func (p *Process) CmdlineWithContext(ctx context.Context) (string, error) { @@ -216,6 +220,16 @@ func (p *Process) fillFromPathCwdWithContext(ctx context.Context) (string, error return cwd, nil } +func (p *Process) fillFromPathAOutWithContext(ctx context.Context) (string, error) { + pid := p.Pid + cwdPath := common.HostProc(strconv.Itoa(int(pid)), "path", "a.out") + exe, err := os.Readlink(cwdPath) + if err != nil { + return "", err + } + return exe, nil +} + func (p *Process) fillFromExecnameWithContext(ctx context.Context) (string, error) { pid := p.Pid execNamePath := common.HostProc(strconv.Itoa(int(pid)), "execname")