files: Remove O_CLOEXEC from file flags

The kernel artificially adds the O_CLOEXEC flag when reading from the
/proc/fdinfo/fd interface if FD_CLOEXEC is set on the file descriptor
used to access the file.

This commit removes the O_CLOEXEC flag in our file flags.

To restore the proper FD_CLOEXEC value in each of the file descriptors,
CRIU uses fcntl(F_GETFD) to retrieve the FD_CLOEXEC status, and restore
it later with fcntl(F_SETFD). This is necessary because multiple file
descriptors may point to the same open file.
This commit is contained in:
Nicolas Viennot 2019-12-30 20:29:27 +00:00 committed by Andrei Vagin
parent 2ac43cd426
commit 8255caf27b

View file

@ -382,7 +382,13 @@ static int fill_fd_params(struct pid *owner_pid, int fd, int lfd,
p->fs_type = fsbuf.f_type;
p->fd = fd;
p->pos = fdinfo.pos;
p->flags = fdinfo.flags;
/*
* The kernel artificially adds the O_CLOEXEC flag on the file pointer
* flags by looking at the flags on the file descriptor (see kernel
* code fs/proc/fd.c). FD_CLOEXEC is a file descriptor property, which
* is saved in fd_flags.
*/
p->flags = fdinfo.flags & ~O_CLOEXEC;
p->mnt_id = fdinfo.mnt_id;
p->pid = owner_pid->real;
p->fd_flags = opts->flags;