casaroli commented on code in PR #21530:
URL: https://github.com/apache/nuttx/pull/21530#discussion_r4499343382


##########
fs/inode/fs_files.c:
##########
@@ -797,9 +797,13 @@ int fdlist_copy(FAR struct fdlist *plist, FAR struct 
fdlist *clist,
               return ret;
             }
 
-          /* Assign filep to the child's descriptor list. Omit the flags */
+          /* Assign filep to the child's descriptor list.  A fork() child
+           * keeps the close-on-exec flag of each descriptor (POSIX); the
+           * descriptors that exec() and posix_spawn() keep have none.
+           */
 
-          fdlist_install(clist, fd, filep, fdp, 0, true);
+          fdlist_install(clist, fd, filep, fdp,
+                         !cloexec && fdp->f_cloexec ? O_CLOEXEC : 0, true);

Review Comment:
   `cloexec` is true for exec() and posix_spawn(), and there a close-on-exec 
descriptor is still copied when a dup2 file action uses it as the source 
(`spawn_file_is_duplicateable()`, sched/task/task_spawnparms.c:337). Without 
the `!`, that copy would now keep `O_CLOEXEC`; with it, exec() and 
posix_spawn() copy the descriptors as before, and only fork() and vfork() keep 
the flag.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to