From 57d4c8a90a115a163f3bae26dfc703c07039807c Mon Sep 17 00:00:00 2001 From: shirou Date: Tue, 14 May 2024 22:56:17 +0900 Subject: [PATCH] [process][openbsd]: add cwd on openbsd. --- process/process_openbsd.go | 7 ++++++- process/process_openbsd_386.go | 1 + process/process_openbsd_amd64.go | 1 + process/process_openbsd_arm.go | 1 + process/process_openbsd_arm64.go | 1 + process/process_openbsd_riscv64.go | 1 + process/types_openbsd.go | 1 + 7 files changed, 12 insertions(+), 1 deletion(-) diff --git a/process/process_openbsd.go b/process/process_openbsd.go index a58c5eb11..358694063 100644 --- a/process/process_openbsd.go +++ b/process/process_openbsd.go @@ -68,7 +68,12 @@ func (p *Process) NameWithContext(ctx context.Context) (string, error) { } func (p *Process) CwdWithContext(ctx context.Context) (string, error) { - return "", common.ErrNotImplementedError + mib := []int32{CTLKern, KernProcCwd, p.Pid} + buf, _, err := common.CallSyscall(mib) + if err != nil { + return "", err + } + return common.ByteToString(buf), nil } func (p *Process) ExeWithContext(ctx context.Context) (string, error) { diff --git a/process/process_openbsd_386.go b/process/process_openbsd_386.go index f4ed02491..6e9edc202 100644 --- a/process/process_openbsd_386.go +++ b/process/process_openbsd_386.go @@ -14,6 +14,7 @@ const ( KernProcProc = 8 KernProcPathname = 12 KernProcArgs = 55 + KernProcCwd = 78 KernProcArgv = 1 KernProcEnv = 3 ) diff --git a/process/process_openbsd_amd64.go b/process/process_openbsd_amd64.go index 8607422b5..a46d28af5 100644 --- a/process/process_openbsd_amd64.go +++ b/process/process_openbsd_amd64.go @@ -11,6 +11,7 @@ const ( KernProcProc = 8 KernProcPathname = 12 KernProcArgs = 55 + KernProcCwd = 78 KernProcArgv = 1 KernProcEnv = 3 ) diff --git a/process/process_openbsd_arm.go b/process/process_openbsd_arm.go index b94429f2e..68ea3c8f7 100644 --- a/process/process_openbsd_arm.go +++ b/process/process_openbsd_arm.go @@ -14,6 +14,7 @@ const ( KernProcProc = 8 KernProcPathname = 12 KernProcArgs = 55 + KernProcCwd = 78 KernProcArgv = 1 KernProcEnv = 3 ) diff --git a/process/process_openbsd_arm64.go b/process/process_openbsd_arm64.go index a3291b8ca..fa620ff67 100644 --- a/process/process_openbsd_arm64.go +++ b/process/process_openbsd_arm64.go @@ -14,6 +14,7 @@ const ( KernProcProc = 8 KernProcPathname = 12 KernProcArgs = 55 + KernProcCwd = 78 KernProcArgv = 1 KernProcEnv = 3 ) diff --git a/process/process_openbsd_riscv64.go b/process/process_openbsd_riscv64.go index 076f095ea..b677e70ad 100644 --- a/process/process_openbsd_riscv64.go +++ b/process/process_openbsd_riscv64.go @@ -14,6 +14,7 @@ const ( KernProcProc = 8 KernProcPathname = 12 KernProcArgs = 55 + KernProcCwd = 78 KernProcArgv = 1 KernProcEnv = 3 ) diff --git a/process/types_openbsd.go b/process/types_openbsd.go index 75f2344a9..ce771bc7a 100644 --- a/process/types_openbsd.go +++ b/process/types_openbsd.go @@ -44,6 +44,7 @@ const ( KernProcProc = 8 // only return procs KernProcPathname = 12 // path to executable KernProcArgs = 55 // get/set arguments/proctitle + KernProcCwd = 78 // get current working directory KernProcArgv = 1 KernProcEnv = 3 )