From a7a0167716d71895919021692b15bd000f63b24f Mon Sep 17 00:00:00 2001 From: Andrei Vagin Date: Tue, 31 Jul 2018 11:18:02 -0700 Subject: 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 --- pkg/sentry/kernel/fd_map.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'pkg/sentry/kernel') diff --git a/pkg/sentry/kernel/fd_map.go b/pkg/sentry/kernel/fd_map.go index ef73125fd..299506330 100644 --- a/pkg/sentry/kernel/fd_map.go +++ b/pkg/sentry/kernel/fd_map.go @@ -51,6 +51,22 @@ type FDFlags struct { CloseOnExec bool } +// ToLinuxFileFlags converts a kernel.FDFlags object to a Linux file flags representation. +func (f FDFlags) ToLinuxFileFlags() (mask uint) { + if f.CloseOnExec { + mask |= linux.O_CLOEXEC + } + return +} + +// ToLinuxFDFlags converts a kernel.FDFlags object to a Linux descriptor flags representation. +func (f FDFlags) ToLinuxFDFlags() (mask uint) { + if f.CloseOnExec { + mask |= linux.FD_CLOEXEC + } + return +} + // descriptor holds the details about a file descriptor, namely a pointer the // file itself and the descriptor flags. type descriptor struct { -- cgit v1.2.3