From 72ef1d7c06ac4c951eaab85f504ec07ff360fd15 Mon Sep 17 00:00:00 2001 From: sin-ack Date: Sun, 6 Feb 2022 17:54:24 +0000 Subject: SystemServer: Remove Socket.h header + use Core::System in some places Various Core::System functions are still missing so not all raw syscalls were converted just yet. --- Userland/Services/SystemServer/Service.cpp | 44 ++++++++++++------------------ 1 file changed, 17 insertions(+), 27 deletions(-) diff --git a/Userland/Services/SystemServer/Service.cpp b/Userland/Services/SystemServer/Service.cpp index c2821fdbee..df8b50b3e1 100644 --- a/Userland/Services/SystemServer/Service.cpp +++ b/Userland/Services/SystemServer/Service.cpp @@ -12,7 +12,8 @@ #include #include #include -#include +#include +#include #include #include #include @@ -39,25 +40,17 @@ void Service::setup_socket(SocketDescriptor& socket) // Note: we use SOCK_CLOEXEC here to make sure we don't leak every socket to // all the clients. We'll make the one we do need to pass down !CLOEXEC later // after forking off the process. - int socket_fd = ::socket(AF_LOCAL, SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0); - if (socket_fd < 0) { - perror("socket"); - VERIFY_NOT_REACHED(); - } + int socket_fd = Core::System::socket(AF_LOCAL, SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0).release_value_but_fixme_should_propagate_errors(); socket.fd = socket_fd; if (m_account.has_value()) { auto& account = m_account.value(); - if (fchown(socket_fd, account.uid(), account.gid()) < 0) { - perror("fchown"); - VERIFY_NOT_REACHED(); - } + // FIXME: Propagate errors + MUST(Core::System::fchown(socket_fd, account.uid(), account.gid())); } - if (fchmod(socket_fd, socket.permissions) < 0) { - perror("fchmod"); - VERIFY_NOT_REACHED(); - } + // FIXME: Propagate errors + MUST(Core::System::fchmod(socket_fd, socket.permissions)); auto socket_address = Core::SocketAddress::local(socket.path); auto un_optional = socket_address.to_sockaddr_un(); @@ -66,17 +59,11 @@ void Service::setup_socket(SocketDescriptor& socket) VERIFY_NOT_REACHED(); } auto un = un_optional.value(); - int rc = bind(socket_fd, (const sockaddr*)&un, sizeof(un)); - if (rc < 0) { - perror("bind"); - VERIFY_NOT_REACHED(); - } - rc = listen(socket_fd, 16); - if (rc < 0) { - perror("listen"); - VERIFY_NOT_REACHED(); - } + // FIXME: Propagate errors + MUST(Core::System::bind(socket_fd, (const sockaddr*)&un, sizeof(un))); + // FIXME: Propagate errors + MUST(Core::System::listen(socket_fd, 16)); } void Service::setup_sockets() @@ -105,11 +92,14 @@ void Service::handle_socket_connection() int socket_fd = m_sockets[0].fd; if (m_accept_socket_connections) { - int accepted_fd = accept(socket_fd, nullptr, nullptr); - if (accepted_fd < 0) { - perror("accept"); + // FIXME: Propagate errors + auto maybe_accepted_fd = Core::System::accept(socket_fd, nullptr, nullptr); + if (maybe_accepted_fd.is_error()) { + dbgln("accept: {}", maybe_accepted_fd.error()); return; } + + int accepted_fd = maybe_accepted_fd.release_value(); spawn(accepted_fd); close(accepted_fd); } else { -- cgit v1.2.3