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.
This commit is contained in:
sin-ack 2022-02-06 17:54:24 +00:00 committed by Andreas Kling
parent 37658e6fa6
commit 72ef1d7c06
Notes: sideshowbarker 2024-07-17 18:50:51 +09:00

View File

@ -12,7 +12,8 @@
#include <AK/StringBuilder.h>
#include <LibCore/ConfigFile.h>
#include <LibCore/File.h>
#include <LibCore/Socket.h>
#include <LibCore/SocketAddress.h>
#include <LibCore/System.h>
#include <fcntl.h>
#include <sched.h>
#include <stdio.h>
@ -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 {