Skip to content

Commit 72372ed

Browse files
committed
refactor(internal/utils/executil): add procfs for exec
1 parent 953146a commit 72372ed

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

internal/utils/executil/exec.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import (
2020
"path/filepath"
2121
"runtime"
2222

23+
"huatuo-bamai/internal/procfs"
24+
2325
"golang.org/x/sys/unix"
2426
)
2527

@@ -34,7 +36,7 @@ func RunningDir() (string, error) {
3436

3537
func HostnameByPid(pid uint32) (string, error) {
3638
var empty string
37-
fd, err := os.Open(fmt.Sprintf("/proc/%d/ns/uts", pid))
39+
fd, err := os.Open(procfs.Path(fmt.Sprintf("%d", pid), "ns/uts"))
3840
if err != nil {
3941
return empty, err
4042
}
@@ -50,7 +52,7 @@ func HostnameByPid(pid uint32) (string, error) {
5052
}
5153

5254
func ProcNameByPid(pid uint32) (string, error) {
53-
data, err := os.ReadFile(fmt.Sprintf("/proc/%d/cmdline", pid))
55+
data, err := os.ReadFile(procfs.Path(fmt.Sprintf("%d", pid), "cmdline"))
5456
if err != nil {
5557
return "", err
5658
}

0 commit comments

Comments
 (0)