LibCore: Do not assert that we can start the RPC server

Now that the Shell uses Core::EventLoop, we can't afford to just crash if /tmp
is unwritable.
This commit is contained in:
Sergey Bugaev 2020-05-28 18:19:49 +03:00 committed by Andreas Kling
parent 53647e347f
commit 8afcf0d87a
Notes: sideshowbarker 2024-07-19 06:00:35 +09:00
3 changed files with 22 additions and 15 deletions

View File

@ -233,20 +233,10 @@ EventLoop::EventLoop()
ASSERT(rc == 0);
s_event_loop_stack->append(this);
auto rpc_path = String::format("/tmp/rpc.%d", getpid());
rc = unlink(rpc_path.characters());
if (rc < 0 && errno != ENOENT) {
perror("unlink");
ASSERT_NOT_REACHED();
if (!s_rpc_server) {
if (!start_rpc_server())
dbg() << "Core::EventLoop: Failed to start an RPC server";
}
s_rpc_server = LocalServer::construct();
s_rpc_server->set_name("Core::EventLoop_RPC_server");
bool listening = s_rpc_server->listen(rpc_path);
ASSERT(listening);
s_rpc_server->on_ready_to_accept = [&] {
RPCClient::construct(s_rpc_server->accept());
};
}
#ifdef CEVENTLOOP_DEBUG
@ -258,6 +248,22 @@ EventLoop::~EventLoop()
{
}
bool EventLoop::start_rpc_server()
{
auto rpc_path = String::format("/tmp/rpc.%d", getpid());
int rc = unlink(rpc_path.characters());
if (rc < 0 && errno != ENOENT) {
perror("unlink");
return false;
}
s_rpc_server = LocalServer::construct();
s_rpc_server->set_name("Core::EventLoop_RPC_server");
s_rpc_server->on_ready_to_accept = [&] {
RPCClient::construct(s_rpc_server->accept());
};
return s_rpc_server->listen(rpc_path);
}
EventLoop& EventLoop::main()
{
ASSERT(s_main_event_loop);

View File

@ -76,6 +76,7 @@ public:
static void wake();
private:
bool start_rpc_server();
void wait_for_event(WaitMode);
Optional<struct timeval> get_next_timer_expiration();

View File

@ -123,13 +123,13 @@ bool LocalServer::listen(const String& address)
rc = ::bind(m_fd, (const sockaddr*)&un, sizeof(un));
if (rc < 0) {
perror("bind");
ASSERT_NOT_REACHED();
return false;
}
rc = ::listen(m_fd, 5);
if (rc < 0) {
perror("listen");
ASSERT_NOT_REACHED();
return false;
}
m_listening = true;