Opened 4 years ago

Closed 2 years ago

Last modified 8 months ago

#12187 closed enhancement (fixed)

F_DUPFD_CLOEXEC missing

Reported by: haiqu Owned by: nobody
Priority: low Milestone: R1
Component: System/POSIX Version: R1/Development
Keywords: Cc:
Blocked By: Blocking:
Has a Patch: no Platform: All

Description

fcntl.h should define F_DUPFD_CLOEXEC, see Posix 2008

Change History (4)

comment:1 Changed 4 years ago by waddlesplash

Component: - GeneralSystem/POSIX
Milestone: UnscheduledR2
Priority: normallow
Type: taskenhancement

comment:2 Changed 2 years ago by korli

Proposed patch:

diff --git a/headers/posix/fcntl.h b/headers/posix/fcntl.h
index ad762f5..7e0805f 100644
--- a/headers/posix/fcntl.h
+++ b/headers/posix/fcntl.h
@@ -20,6 +20,7 @@
 #define F_GETLK         0x0020         /* get locking information */
 #define F_SETLK         0x0080         /* set locking information */
 #define F_SETLKW        0x0100         /* as above, but waits if blocked */
+#define        F_DUPFD_CLOEXEC 0x0200          /* duplicate fd with close on exec set */
 
 /* advisory locking types */
 #define F_RDLCK         0x0040         /* read or shared lock */
diff --git a/src/system/kernel/fs/vfs.cpp b/src/system/kernel/fs/vfs.cpp
index ea47773..35b7d90 100644
--- a/src/system/kernel/fs/vfs.cpp
+++ b/src/system/kernel/fs/vfs.cpp
@@ -6147,13 +6147,14 @@ common_fcntl(int fd, int op, size_t argument, bool kernel)
                        break;
 
                case F_DUPFD:
+               case F_DUPFD_CLOEXEC:
                {
                        struct io_context* context = get_current_io_context(kernel);
 
                        status = new_fd_etc(context, descriptor, (int)argument);
                        if (status >= 0) {
                                mutex_lock(&context->io_mutex);
-                               fd_set_close_on_exec(context, fd, false);
+                               fd_set_close_on_exec(context, fd, op == F_DUPFD_CLOEXEC);
                                mutex_unlock(&context->io_mutex);
 
                                atomic_add(&descriptor->ref_count, 1);

comment:3 Changed 2 years ago by korli

Resolution: fixed
Status: newclosed

Applied in hrev51372.

comment:4 Changed 8 months ago by pulkomandy

Milestone: R2R1
Note: See TracTickets for help on using tickets.