mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-23 08:00:20 +00:00
Kernel: Support F_DUPFD_CLOEXEC command to fcntl(2)
Specified by POSIX: https://pubs.opengroup.org/onlinepubs/9699919799/functions/fcntl.html
This commit is contained in:
parent
22c0e6b60e
commit
2808b03764
Notes:
sideshowbarker
2024-07-17 01:12:07 +09:00
Author: https://github.com/petelliott Commit: https://github.com/SerenityOS/serenity/commit/2808b03764 Pull-request: https://github.com/SerenityOS/serenity/pull/17471 Reviewed-by: https://github.com/ADKaster Reviewed-by: https://github.com/linusg
2 changed files with 3 additions and 1 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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;
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue