mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 13:47:35 +00:00
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:
parent
37658e6fa6
commit
72ef1d7c06
1 changed files with 17 additions and 27 deletions
|
@ -12,7 +12,8 @@
|
||||||
#include <AK/StringBuilder.h>
|
#include <AK/StringBuilder.h>
|
||||||
#include <LibCore/ConfigFile.h>
|
#include <LibCore/ConfigFile.h>
|
||||||
#include <LibCore/File.h>
|
#include <LibCore/File.h>
|
||||||
#include <LibCore/Socket.h>
|
#include <LibCore/SocketAddress.h>
|
||||||
|
#include <LibCore/System.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <sched.h>
|
#include <sched.h>
|
||||||
#include <stdio.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
|
// 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
|
// all the clients. We'll make the one we do need to pass down !CLOEXEC later
|
||||||
// after forking off the process.
|
// after forking off the process.
|
||||||
int socket_fd = ::socket(AF_LOCAL, SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0);
|
int socket_fd = Core::System::socket(AF_LOCAL, SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0).release_value_but_fixme_should_propagate_errors();
|
||||||
if (socket_fd < 0) {
|
|
||||||
perror("socket");
|
|
||||||
VERIFY_NOT_REACHED();
|
|
||||||
}
|
|
||||||
socket.fd = socket_fd;
|
socket.fd = socket_fd;
|
||||||
|
|
||||||
if (m_account.has_value()) {
|
if (m_account.has_value()) {
|
||||||
auto& account = m_account.value();
|
auto& account = m_account.value();
|
||||||
if (fchown(socket_fd, account.uid(), account.gid()) < 0) {
|
// FIXME: Propagate errors
|
||||||
perror("fchown");
|
MUST(Core::System::fchown(socket_fd, account.uid(), account.gid()));
|
||||||
VERIFY_NOT_REACHED();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fchmod(socket_fd, socket.permissions) < 0) {
|
// FIXME: Propagate errors
|
||||||
perror("fchmod");
|
MUST(Core::System::fchmod(socket_fd, socket.permissions));
|
||||||
VERIFY_NOT_REACHED();
|
|
||||||
}
|
|
||||||
|
|
||||||
auto socket_address = Core::SocketAddress::local(socket.path);
|
auto socket_address = Core::SocketAddress::local(socket.path);
|
||||||
auto un_optional = socket_address.to_sockaddr_un();
|
auto un_optional = socket_address.to_sockaddr_un();
|
||||||
|
@ -66,17 +59,11 @@ void Service::setup_socket(SocketDescriptor& socket)
|
||||||
VERIFY_NOT_REACHED();
|
VERIFY_NOT_REACHED();
|
||||||
}
|
}
|
||||||
auto un = un_optional.value();
|
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);
|
// FIXME: Propagate errors
|
||||||
if (rc < 0) {
|
MUST(Core::System::bind(socket_fd, (const sockaddr*)&un, sizeof(un)));
|
||||||
perror("listen");
|
// FIXME: Propagate errors
|
||||||
VERIFY_NOT_REACHED();
|
MUST(Core::System::listen(socket_fd, 16));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Service::setup_sockets()
|
void Service::setup_sockets()
|
||||||
|
@ -105,11 +92,14 @@ void Service::handle_socket_connection()
|
||||||
int socket_fd = m_sockets[0].fd;
|
int socket_fd = m_sockets[0].fd;
|
||||||
|
|
||||||
if (m_accept_socket_connections) {
|
if (m_accept_socket_connections) {
|
||||||
int accepted_fd = accept(socket_fd, nullptr, nullptr);
|
// FIXME: Propagate errors
|
||||||
if (accepted_fd < 0) {
|
auto maybe_accepted_fd = Core::System::accept(socket_fd, nullptr, nullptr);
|
||||||
perror("accept");
|
if (maybe_accepted_fd.is_error()) {
|
||||||
|
dbgln("accept: {}", maybe_accepted_fd.error());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int accepted_fd = maybe_accepted_fd.release_value();
|
||||||
spawn(accepted_fd);
|
spawn(accepted_fd);
|
||||||
close(accepted_fd);
|
close(accepted_fd);
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue