summaryrefslogtreecommitdiffhomepage
path: root/pkg/sentry/fs/proc
diff options
context:
space:
mode:
authorAndrei Vagin <avagin@gmail.com>2018-07-31 11:18:02 -0700
committerShentubot <shentubot@google.com>2018-07-31 11:19:15 -0700
commita7a0167716d71895919021692b15bd000f63b24f (patch)
tree5e41d11fe25b533a59387649e4f90c0801e1eb1e /pkg/sentry/fs/proc
parent543c997978525ac7de3a24ff73203ddbb2cef6dc (diff)
proc: show file flags in fdinfo
Currently, there is an attempt to print FD flags, but they are not decoded into a number, so we see something like this: /criu # cat /proc/self/fdinfo/0 flags: {%!o(bool=000false)} Actually, fdinfo has to contain file flags. Change-Id: Idcbb7db908067447eb9ae6f2c3cfb861f2be1a97 PiperOrigin-RevId: 206794498
Diffstat (limited to 'pkg/sentry/fs/proc')
-rw-r--r--pkg/sentry/fs/proc/fds.go21
1 files changed, 12 insertions, 9 deletions
diff --git a/pkg/sentry/fs/proc/fds.go b/pkg/sentry/fs/proc/fds.go
index 2eca9ac31..194a9c12a 100644
--- a/pkg/sentry/fs/proc/fds.go
+++ b/pkg/sentry/fs/proc/fds.go
@@ -40,16 +40,16 @@ func walkDescriptors(t *kernel.Task, p string, toInode func(*fs.File, kernel.FDF
}
var file *fs.File
- var flags kernel.FDFlags
+ var fdFlags kernel.FDFlags
t.WithMuLocked(func(t *kernel.Task) {
if fdm := t.FDMap(); fdm != nil {
- file, flags = fdm.GetDescriptor(kdefs.FD(n))
+ file, fdFlags = fdm.GetDescriptor(kdefs.FD(n))
}
})
if file == nil {
return nil, syserror.ENOENT
}
- return toInode(file, flags), nil
+ return toInode(file, fdFlags), nil
}
// readDescriptors reads fds in the task starting at offset, and calls the
@@ -200,17 +200,20 @@ func (f *fdDir) DeprecatedReaddir(ctx context.Context, dirCtx *fs.DirCtx, offset
type fdInfo struct {
ramfs.File
- flags kernel.FDFlags
+ flags fs.FileFlags
+ fdFlags kernel.FDFlags
}
// newFdInfo returns a new fdInfo based on an existing file.
-func newFdInfo(t *kernel.Task, _ *fs.File, flags kernel.FDFlags, msrc *fs.MountSource) *fs.Inode {
- fdi := &fdInfo{flags: flags}
+func newFdInfo(t *kernel.Task, file *fs.File, fdFlags kernel.FDFlags, msrc *fs.MountSource) *fs.Inode {
+ fdi := &fdInfo{flags: file.Flags(), fdFlags: fdFlags}
fdi.InitFile(t, fs.RootOwner, fs.FilePermissions{User: fs.PermMask{Read: true}})
// TODO: Get pos, locks, and other data. For now we only
// have flags.
// See https://www.kernel.org/doc/Documentation/filesystems/proc.txt
- fdi.Append([]byte(fmt.Sprintf("flags: %08o\n", flags)))
+
+ flags := file.Flags().ToLinux() | fdFlags.ToLinuxFileFlags()
+ fdi.Append([]byte(fmt.Sprintf("flags:\t0%o\n", flags)))
return newFile(fdi, msrc, fs.SpecialFile, t)
}
@@ -241,8 +244,8 @@ func newFdInfoDir(t *kernel.Task, msrc *fs.MountSource) *fs.Inode {
// Lookup loads an fd in /proc/TID/fdinfo into a Dirent.
func (fdid *fdInfoDir) Lookup(ctx context.Context, dir *fs.Inode, p string) (*fs.Dirent, error) {
- n, err := walkDescriptors(fdid.t, p, func(file *fs.File, flags kernel.FDFlags) *fs.Inode {
- return newFdInfo(fdid.t, file, flags, dir.MountSource)
+ n, err := walkDescriptors(fdid.t, p, func(file *fs.File, fdFlags kernel.FDFlags) *fs.Inode {
+ return newFdInfo(fdid.t, file, fdFlags, dir.MountSource)
})
if err != nil {
return nil, err