mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
committed by
gVisor bot
parent
9dfac31f0a
commit
5deab709e7
@@ -7,6 +7,7 @@ go_library(
|
||||
srcs = ["dump.go"],
|
||||
visibility = ["//runsc:__subpackages__"],
|
||||
deps = [
|
||||
"//pkg/abi/linux",
|
||||
"//pkg/context",
|
||||
"//pkg/log",
|
||||
"//pkg/sentry/fsimpl/proc",
|
||||
|
||||
@@ -21,6 +21,7 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"gvisor.dev/gvisor/pkg/abi/linux"
|
||||
"gvisor.dev/gvisor/pkg/context"
|
||||
"gvisor.dev/gvisor/pkg/log"
|
||||
"gvisor.dev/gvisor/pkg/sentry/fsimpl/proc"
|
||||
@@ -36,6 +37,8 @@ type FDInfo struct {
|
||||
Number int32 `json:"number,omitempty"`
|
||||
// Path is the path of the file that FD represents.
|
||||
Path string `json:"path,omitempty"`
|
||||
// Mode is the file mode.
|
||||
Mode uint16 `json:"mode,omitempty"`
|
||||
}
|
||||
|
||||
// UIDGID contains information for /proc/[pid]/status/{uid,gid}.
|
||||
@@ -185,7 +188,13 @@ func getFDs(ctx context.Context, t *kernel.Task, pid kernel.ThreadID) []FDInfo {
|
||||
log.Warningf("PathnameWithDeleted failed to find path for fd %d in PID %s: %v", fd.no, pid, err)
|
||||
path = ""
|
||||
}
|
||||
res = append(res, FDInfo{Number: fd.no, Path: path})
|
||||
mode := uint16(0)
|
||||
if statx, err := fd.fd.Stat(ctx, vfs.StatOptions{Mask: linux.STATX_MODE}); err != nil {
|
||||
log.Warningf("Stat(STATX_MODE) failed for fd %d in PID %s: %v", fd.no, pid, err)
|
||||
} else {
|
||||
mode = statx.Mode
|
||||
}
|
||||
res = append(res, FDInfo{Number: fd.no, Path: path, Mode: mode})
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import (
|
||||
"time"
|
||||
|
||||
specs "github.com/opencontainers/runtime-spec/specs-go"
|
||||
"golang.org/x/sys/unix"
|
||||
"google.golang.org/protobuf/proto"
|
||||
"gvisor.dev/gvisor/pkg/sentry/kernel"
|
||||
"gvisor.dev/gvisor/pkg/sentry/limits"
|
||||
@@ -374,12 +375,16 @@ func TestProcfsDump(t *testing.T) {
|
||||
if len(procfsDump[0].FDs) < 3 {
|
||||
t.Errorf("expected at least 3 FDs for the sleep process, got %+v", procfsDump[0].FDs)
|
||||
} else {
|
||||
modes := []uint16{unix.S_IFCHR, unix.S_IFIFO, unix.S_IFREG}
|
||||
for i, fd := range procfsDump[0].FDs[:3] {
|
||||
if want := int32(i); fd.Number != want {
|
||||
t.Errorf("expected FD number %d, got %d", want, fd.Number)
|
||||
}
|
||||
if wantSubStr := "host"; !strings.Contains(fd.Path, wantSubStr) {
|
||||
t.Errorf("expected FD path to contain %q, got %q", wantSubStr, fd.Path)
|
||||
t.Errorf("expected FD %d path to contain %q, got %q", fd.Number, wantSubStr, fd.Path)
|
||||
}
|
||||
if want, got := modes[i], fd.Mode&unix.S_IFMT; uint16(want) != got {
|
||||
t.Errorf("wrong mode FD %d, want: %#o, got: %#o", fd.Number, want, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user