mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-10 21:53:57 +08:00
libct/system: use securejoin for /proc/$pid/stat
Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
This commit is contained in:
@@ -2,10 +2,12 @@ package system
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/opencontainers/runc/internal/pathrs"
|
||||||
)
|
)
|
||||||
|
|
||||||
// State is the status of a process.
|
// State is the status of a process.
|
||||||
@@ -66,8 +68,16 @@ type Stat_t struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Stat returns a Stat_t instance for the specified process.
|
// Stat returns a Stat_t instance for the specified process.
|
||||||
func Stat(pid int) (stat Stat_t, err error) {
|
func Stat(pid int) (Stat_t, error) {
|
||||||
bytes, err := os.ReadFile(filepath.Join("/proc", strconv.Itoa(pid), "stat"))
|
var stat Stat_t
|
||||||
|
|
||||||
|
statFile, err := pathrs.ProcPidOpen(pid, "stat", os.O_RDONLY)
|
||||||
|
if err != nil {
|
||||||
|
return stat, err
|
||||||
|
}
|
||||||
|
defer statFile.Close()
|
||||||
|
|
||||||
|
bytes, err := io.ReadAll(statFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return stat, err
|
return stat, err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user