diff options
author | Peter Elliott <pelliott@ualberta.ca> | 2023-02-11 14:17:41 -0700 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2023-02-19 00:37:37 +0100 |
commit | 2808b0376406a40e31293bb3bcb9170374e90506 (patch) | |
tree | bb818055e6c3159ac656695c8643b804f95f709d /Kernel | |
parent | 22c0e6b60ee791c8109814a91322a3bf47a91cd9 (diff) | |
download | serenity-2808b0376406a40e31293bb3bcb9170374e90506.zip |
Kernel: Support F_DUPFD_CLOEXEC command to fcntl(2)
Specified by POSIX:
https://pubs.opengroup.org/onlinepubs/9699919799/functions/fcntl.html
Diffstat (limited to 'Kernel')
-rw-r--r-- | Kernel/API/POSIX/fcntl.h | 1 | ||||
-rw-r--r-- | Kernel/Syscalls/fcntl.cpp | 3 |
2 files changed, 3 insertions, 1 deletions
diff --git a/Kernel/API/POSIX/fcntl.h b/Kernel/API/POSIX/fcntl.h index 1aa225a789..cea7461ebc 100644 --- a/Kernel/API/POSIX/fcntl.h +++ b/Kernel/API/POSIX/fcntl.h @@ -21,6 +21,7 @@ extern "C" { #define F_GETLK 6 #define F_SETLK 7 #define F_SETLKW 8 +#define F_DUPFD_CLOEXEC 9 #define FD_CLOEXEC 1 diff --git a/Kernel/Syscalls/fcntl.cpp b/Kernel/Syscalls/fcntl.cpp index 1fb961116a..4523f969cb 100644 --- a/Kernel/Syscalls/fcntl.cpp +++ b/Kernel/Syscalls/fcntl.cpp @@ -19,13 +19,14 @@ ErrorOr<FlatPtr> Process::sys$fcntl(int fd, int cmd, uintptr_t arg) // NOTE: The FD flags are not shared between OpenFileDescription objects. // This means that dup() doesn't copy the FD_CLOEXEC flag! switch (cmd) { + case F_DUPFD_CLOEXEC: case F_DUPFD: { int arg_fd = (int)arg; if (arg_fd < 0) return EINVAL; return m_fds.with_exclusive([&](auto& fds) -> ErrorOr<FlatPtr> { auto fd_allocation = TRY(fds.allocate(arg_fd)); - fds[fd_allocation.fd].set(*description); + fds[fd_allocation.fd].set(*description, (cmd == F_DUPFD_CLOEXEC) ? FD_CLOEXEC : 0); return fd_allocation.fd; }); } |