summaryrefslogtreecommitdiff
path: root/Kernel/Syscalls/sendfd.cpp
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-09-05 18:34:28 +0200
committerAndreas Kling <kling@serenityos.org>2021-09-05 18:36:13 +0200
commita9204510a4c0c37588a38201f305d7e9b4e762a9 (patch)
tree752b1077191f2608755104f6cca2a19bc9f4591c /Kernel/Syscalls/sendfd.cpp
parent2d2ea05c97e97848f431b5c9e5f709fe276eb7c8 (diff)
downloadserenity-a9204510a4c0c37588a38201f305d7e9b4e762a9.zip
Kernel: Make file description lookup return KResultOr
Instead of checking it at every call site (to generate EBADF), we make file_description(fd) return a KResultOr<NonnullRefPtr<FileDescription>>. This allows us to wrap all the calls in TRY(). :^) The only place that got a little bit messier from this is sys$mount(), and there's a whole bunch of things there in need of cleanup.
Diffstat (limited to 'Kernel/Syscalls/sendfd.cpp')
-rw-r--r--Kernel/Syscalls/sendfd.cpp13
1 files changed, 3 insertions, 10 deletions
diff --git a/Kernel/Syscalls/sendfd.cpp b/Kernel/Syscalls/sendfd.cpp
index fd82027f4f..6c0fed3cac 100644
--- a/Kernel/Syscalls/sendfd.cpp
+++ b/Kernel/Syscalls/sendfd.cpp
@@ -14,9 +14,7 @@ KResultOr<FlatPtr> Process::sys$sendfd(int sockfd, int fd)
{
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this)
REQUIRE_PROMISE(sendfd);
- auto socket_description = fds().file_description(sockfd);
- if (!socket_description)
- return EBADF;
+ auto socket_description = TRY(fds().file_description(sockfd));
if (!socket_description->is_socket())
return ENOTSOCK;
auto& socket = *socket_description->socket();
@@ -25,10 +23,7 @@ KResultOr<FlatPtr> Process::sys$sendfd(int sockfd, int fd)
if (!socket.is_connected())
return ENOTCONN;
- auto passing_descriptor = fds().file_description(fd);
- if (!passing_descriptor)
- return EBADF;
-
+ auto passing_descriptor = TRY(fds().file_description(fd));
auto& local_socket = static_cast<LocalSocket&>(socket);
return local_socket.sendfd(*socket_description, *passing_descriptor);
}
@@ -37,9 +32,7 @@ KResultOr<FlatPtr> Process::sys$recvfd(int sockfd, int options)
{
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this)
REQUIRE_PROMISE(recvfd);
- auto socket_description = fds().file_description(sockfd);
- if (!socket_description)
- return EBADF;
+ auto socket_description = TRY(fds().file_description(sockfd));
if (!socket_description->is_socket())
return ENOTSOCK;
auto& socket = *socket_description->socket();