From 26740b28893de8d58bbff5442b2b0809db4ab0bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Duval?= Date: Thu, 24 Aug 2017 17:46:45 +0200 Subject: [PATCH] POSIX: F_DUPFD_CLOEXEC support (POSIX.1-2008). * fix #12187. --- headers/posix/fcntl.h | 1 + src/system/kernel/fs/vfs.cpp | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/headers/posix/fcntl.h b/headers/posix/fcntl.h index ad762f5b0d..d86ca2be4e 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 ea477739d4..35b7d908c0 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);