Skip to content

Commit

Permalink
Merge pull request #1075 from scop/feat/improve-solaris-exe
Browse files Browse the repository at this point in the history
[process][solaris] improve Exe portability
  • Loading branch information
shirou committed May 29, 2021
2 parents 8775def + f43138a commit 7ffa844
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
16 changes: 15 additions & 1 deletion process/process_solaris.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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")
Expand Down
16 changes: 15 additions & 1 deletion v3/process/process_solaris.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 7ffa844

Please sign in to comment.