POSIX: F_DUPFD_CLOEXEC support (POSIX.1-2008).

* fix #12187.
This commit is contained in:
Jérôme Duval 2017-08-24 17:46:45 +02:00
parent a74f88cf8f
commit 26740b2889
2 changed files with 3 additions and 1 deletions

View File

@ -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 */

View File

@ -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);