From dc2dac237777bba512fc684268fdd63dbf032370 Mon Sep 17 00:00:00 2001 From: dongjiuzhu1 Date: Sat, 21 Oct 2023 21:46:54 +0800 Subject: [PATCH] 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 --- fs/vfs/fs_dup2.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/fs/vfs/fs_dup2.c b/fs/vfs/fs_dup2.c index 8257382660..95ad2a4d1b 100644 --- a/fs/vfs/fs_dup2.c +++ b/fs/vfs/fs_dup2.c @@ -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;