diff options
author | Andrei Vagin <avagin@google.com> | 2020-06-12 11:56:43 -0700 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2020-06-12 11:58:15 -0700 |
commit | 6ec9d60403fdf7a33072eaa023e62bfd56ed9f5c (patch) | |
tree | 7ee6a2d602ee63d8a34fe955719ca4ece7e0aa6a /pkg/sentry/kernel/fd_table.go | |
parent | 61d6c059ac3434ddf0c206975a116a09d0838338 (diff) |
vfs2: implement fcntl(fd, F_SETFL, flags)
PiperOrigin-RevId: 316148074
Diffstat (limited to 'pkg/sentry/kernel/fd_table.go')
-rw-r--r-- | pkg/sentry/kernel/fd_table.go | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/pkg/sentry/kernel/fd_table.go b/pkg/sentry/kernel/fd_table.go index b35afafe3..48911240f 100644 --- a/pkg/sentry/kernel/fd_table.go +++ b/pkg/sentry/kernel/fd_table.go @@ -458,6 +458,29 @@ func (f *FDTable) SetFlags(fd int32, flags FDFlags) error { return nil } +// SetFlagsVFS2 sets the flags for the given file descriptor. +// +// True is returned iff flags were changed. +func (f *FDTable) SetFlagsVFS2(fd int32, flags FDFlags) error { + if fd < 0 { + // Don't accept negative FDs. + return syscall.EBADF + } + + f.mu.Lock() + defer f.mu.Unlock() + + file, _, _ := f.getVFS2(fd) + if file == nil { + // No file found. + return syscall.EBADF + } + + // Update the flags. + f.setVFS2(fd, file, flags) + return nil +} + // Get returns a reference to the file and the flags for the FD or nil if no // file is defined for the given fd. // |