Skip to content

Commit

Permalink
[process][freebsd]: add CWD
Browse files Browse the repository at this point in the history
  • Loading branch information
shirou committed Dec 29, 2024
1 parent ab66f2d commit 2aaa68f
Show file tree
Hide file tree
Showing 3 changed files with 211 additions and 157 deletions.
24 changes: 21 additions & 3 deletions process/process_freebsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package process
import (
"bytes"
"context"
"encoding/binary"
"errors"
"path/filepath"
"sort"
Expand All @@ -14,9 +15,9 @@ import (

"golang.org/x/sys/unix"

cpu "github.com/shirou/gopsutil/v4/cpu"
"github.com/shirou/gopsutil/v4/cpu"
"github.com/shirou/gopsutil/v4/internal/common"
net "github.com/shirou/gopsutil/v4/net"
"github.com/shirou/gopsutil/v4/net"
)

func pidsWithContext(ctx context.Context) ([]int32, error) {
Expand Down Expand Up @@ -66,7 +67,24 @@ func (p *Process) NameWithContext(ctx context.Context) (string, error) {
}

func (p *Process) CwdWithContext(ctx context.Context) (string, error) {
return "", common.ErrNotImplementedError
mib := []int32{CTLKern, KernProc, KernProcCwd, p.Pid}

Check failure on line 70 in process/process_freebsd.go

View workflow job for this annotation

GitHub Actions / build_test (1.22.10)

undefined: KernProcCwd

Check failure on line 70 in process/process_freebsd.go

View workflow job for this annotation

GitHub Actions / build_test (1.23.4)

undefined: KernProcCwd
buf, length, err := common.CallSyscall(mib)
if err != nil {
return "", err
}

if length != sizeOfKinfoFile {

Check failure on line 76 in process/process_freebsd.go

View workflow job for this annotation

GitHub Actions / build_test (1.22.10)

undefined: sizeOfKinfoFile

Check failure on line 76 in process/process_freebsd.go

View workflow job for this annotation

GitHub Actions / build_test (1.23.4)

undefined: sizeOfKinfoFile
return "", errors.New("unexpected size of KinfoFile")
}

var k kinfoFile

Check failure on line 80 in process/process_freebsd.go

View workflow job for this annotation

GitHub Actions / build_test (1.22.10)

undefined: kinfoFile

Check failure on line 80 in process/process_freebsd.go

View workflow job for this annotation

GitHub Actions / build_test (1.23.4)

undefined: kinfoFile
br := bytes.NewReader(buf)
if err := common.Read(br, binary.LittleEndian, &k); err != nil {
return "", err
}
cwd := common.IntToString(k.Path[:])

return cwd, nil
}

func (p *Process) ExeWithContext(ctx context.Context) (string, error) {
Expand Down
Loading

0 comments on commit 2aaa68f

Please sign in to comment.