This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit dc2dac237777bba512fc684268fdd63dbf032370
Author: dongjiuzhu1 <dongjiuz...@xiaomi.com>
AuthorDate: Sat Oct 21 21:46:54 2023 +0800

    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 <dongjiuz...@xiaomi.com>
---
 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;
 

Reply via email to