summaryrefslogtreecommitdiffhomepage
path: root/pkg/sentry/syscalls
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/syscalls
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/syscalls')
-rw-r--r--pkg/sentry/syscalls/linux/flags.go43
-rw-r--r--pkg/sentry/syscalls/linux/sys_file.go4
2 files changed, 2 insertions, 45 deletions
diff --git a/pkg/sentry/syscalls/linux/flags.go b/pkg/sentry/syscalls/linux/flags.go
index b2e173f3e..e8db3e0de 100644
--- a/pkg/sentry/syscalls/linux/flags.go
+++ b/pkg/sentry/syscalls/linux/flags.go
@@ -17,7 +17,6 @@ package linux
import (
"gvisor.googlesource.com/gvisor/pkg/abi/linux"
"gvisor.googlesource.com/gvisor/pkg/sentry/fs"
- "gvisor.googlesource.com/gvisor/pkg/sentry/kernel"
)
// flagsToPermissions returns a Permissions object from Linux flags.
@@ -35,48 +34,6 @@ func flagsToPermissions(mask uint) (p fs.PermMask) {
return
}
-// fdFlagsToLinux converts a kernel.FDFlags object to a Linux representation.
-func fdFlagsToLinux(flags kernel.FDFlags) (mask uint) {
- if flags.CloseOnExec {
- mask |= linux.FD_CLOEXEC
- }
- return
-}
-
-// flagsToLinux converts a FileFlags object to a Linux representation.
-func flagsToLinux(flags fs.FileFlags) (mask uint) {
- if flags.Direct {
- mask |= linux.O_DIRECT
- }
- if flags.NonBlocking {
- mask |= linux.O_NONBLOCK
- }
- if flags.Sync {
- mask |= linux.O_SYNC
- }
- if flags.Append {
- mask |= linux.O_APPEND
- }
- if flags.Directory {
- mask |= linux.O_DIRECTORY
- }
- if flags.Async {
- mask |= linux.O_ASYNC
- }
- if flags.LargeFile {
- mask |= linux.O_LARGEFILE
- }
- switch {
- case flags.Read && flags.Write:
- mask |= linux.O_RDWR
- case flags.Write:
- mask |= linux.O_WRONLY
- case flags.Read:
- mask |= linux.O_RDONLY
- }
- return
-}
-
// linuxToFlags converts linux file flags to a FileFlags object.
func linuxToFlags(mask uint) (flags fs.FileFlags) {
return fs.FileFlags{
diff --git a/pkg/sentry/syscalls/linux/sys_file.go b/pkg/sentry/syscalls/linux/sys_file.go
index 2f28fbea6..692f11ed7 100644
--- a/pkg/sentry/syscalls/linux/sys_file.go
+++ b/pkg/sentry/syscalls/linux/sys_file.go
@@ -809,14 +809,14 @@ func Fcntl(t *kernel.Task, args arch.SyscallArguments) (uintptr, *kernel.Syscall
}
return uintptr(fd), nil, nil
case linux.F_GETFD:
- return uintptr(fdFlagsToLinux(flags)), nil, nil
+ return uintptr(flags.ToLinuxFDFlags()), nil, nil
case linux.F_SETFD:
flags := args[2].Uint()
t.FDMap().SetFlags(fd, kernel.FDFlags{
CloseOnExec: flags&syscall.FD_CLOEXEC != 0,
})
case linux.F_GETFL:
- return uintptr(flagsToLinux(file.Flags())), nil, nil
+ return uintptr(file.Flags().ToLinux()), nil, nil
case linux.F_SETFL:
flags := uint(args[2].Uint())
file.SetFlags(linuxToSettableFlags(flags))