fs/dup/dup2: don't add O_CLOEXEC for new file descriptor

refs: https://man7.org/linux/man-pages/man2/dup.2.html

The two file descriptors do not share file descriptor flags (the
close-on-exec flag).  The close-on-exec flag (FD_CLOEXEC; see
fcntl(2)) for the duplicate descriptor is off.

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
This commit is contained in:
dongjiuzhu1 2023-10-21 21:46:54 +08:00 committed by Xiang Xiao
parent 5c98649a7a
commit dc2dac2377

View file

@ -83,7 +83,10 @@ int file_dup2(FAR struct file *filep1, FAR struct file *filep2)
/* Then clone the file structure */
memset(&temp, 0, sizeof(temp));
temp.f_oflags = filep1->f_oflags;
/* The two filep don't share flags (the close-on-exec flag). */
temp.f_oflags = filep1->f_oflags & ~O_CLOEXEC;
temp.f_pos = filep1->f_pos;
temp.f_inode = inode;