We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 435cc81 commit d61fd29Copy full SHA for d61fd29
1 file changed
libcontainer/system/proc.go
@@ -2,10 +2,12 @@ package system
2
3
import (
4
"fmt"
5
+ "io"
6
"os"
- "path/filepath"
7
"strconv"
8
"strings"
9
+
10
+ "github.com/opencontainers/runc/internal/pathrs"
11
)
12
13
// State is the status of a process.
@@ -66,8 +68,16 @@ type Stat_t struct {
66
68
}
67
69
70
// Stat returns a Stat_t instance for the specified process.
-func Stat(pid int) (stat Stat_t, err error) {
- bytes, err := os.ReadFile(filepath.Join("/proc", strconv.Itoa(pid), "stat"))
71
+func Stat(pid int) (Stat_t, error) {
72
+ var stat Stat_t
73
74
+ statFile, err := pathrs.ProcPidOpen(pid, "stat", os.O_RDONLY)
75
+ if err != nil {
76
+ return stat, err
77
+ }
78
+ defer statFile.Close()
79
80
+ bytes, err := io.ReadAll(statFile)
81
if err != nil {
82
return stat, err
83
0 commit comments