summaryrefslogtreecommitdiff
path: root/Kernel/Syscalls/ioctl.cpp
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2022-04-26 14:32:12 +0200
committerAndreas Kling <kling@serenityos.org>2022-04-26 14:32:12 +0200
commitb85c8a0b8091e704ba21fd0631b82a0f6949d612 (patch)
treea06d5b15cec26bf10c1dc8b4076909d55c3905bb /Kernel/Syscalls/ioctl.cpp
parent20d21fad7b39f30ff1de85fc2d1f54cbd91801c0 (diff)
downloadserenity-b85c8a0b8091e704ba21fd0631b82a0f6949d612.zip
Kernel: Add FIOCLEX and FIONCLEX ioctls
These allow you to turn the close-on-exec flag on/off via ioctl().
Diffstat (limited to 'Kernel/Syscalls/ioctl.cpp')
-rw-r--r--Kernel/Syscalls/ioctl.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/Kernel/Syscalls/ioctl.cpp b/Kernel/Syscalls/ioctl.cpp
index 9b333c61d9..ccbe9d7681 100644
--- a/Kernel/Syscalls/ioctl.cpp
+++ b/Kernel/Syscalls/ioctl.cpp
@@ -19,6 +19,18 @@ ErrorOr<FlatPtr> Process::sys$ioctl(int fd, unsigned request, FlatPtr arg)
description->set_blocking(TRY(copy_typed_from_user(Userspace<int const*>(arg))) == 0);
return 0;
}
+ if (request == FIOCLEX) {
+ m_fds.with_exclusive([&](auto& fds) {
+ fds[fd].set_flags(fds[fd].flags() | FD_CLOEXEC);
+ });
+ return 0;
+ }
+ if (request == FIONCLEX) {
+ m_fds.with_exclusive([&](auto& fds) {
+ fds[fd].set_flags(fds[fd].flags() & ~FD_CLOEXEC);
+ });
+ return 0;
+ }
TRY(description->file().ioctl(*description, request, arg));
return 0;
}