2020-04-26 16:27:57 -03:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2020, Nicholas Hollett <niax@niax.co.uk>
|
|
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-04-26 16:27:57 -03:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "ClientConnection.h"
|
|
|
|
|
#include "Launcher.h"
|
|
|
|
|
#include <LibCore/ConfigFile.h>
|
|
|
|
|
#include <LibCore/EventLoop.h>
|
|
|
|
|
#include <LibCore/LocalServer.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
2020-12-20 20:09:48 -03:00
|
|
|
int main([[maybe_unused]] int argc, [[maybe_unused]] char** argv)
|
2020-04-26 16:27:57 -03:00
|
|
|
{
|
|
|
|
|
Core::EventLoop event_loop;
|
|
|
|
|
auto server = Core::LocalServer::construct();
|
|
|
|
|
|
|
|
|
|
auto launcher = LaunchServer::Launcher();
|
|
|
|
|
|
2020-12-27 14:55:01 -03:00
|
|
|
launcher.load_handlers();
|
2021-08-21 11:33:54 -03:00
|
|
|
launcher.load_config(Core::ConfigFile::open_for_app("LaunchServer"));
|
2020-04-26 16:27:57 -03:00
|
|
|
|
|
|
|
|
if (pledge("stdio accept rpath proc exec", nullptr) < 0) {
|
|
|
|
|
perror("pledge");
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ok = server->take_over_from_system_server();
|
2021-02-23 16:42:32 -03:00
|
|
|
VERIFY(ok);
|
2020-04-26 16:27:57 -03:00
|
|
|
server->on_ready_to_accept = [&] {
|
|
|
|
|
auto client_socket = server->accept();
|
|
|
|
|
if (!client_socket) {
|
2021-01-09 14:51:44 -03:00
|
|
|
dbgln("LaunchServer: accept failed.");
|
2020-04-26 16:27:57 -03:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
static int s_next_client_id = 0;
|
|
|
|
|
int client_id = ++s_next_client_id;
|
2020-07-06 08:23:39 -03:00
|
|
|
IPC::new_client_connection<LaunchServer::ClientConnection>(client_socket.release_nonnull(), client_id);
|
2020-04-26 16:27:57 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return event_loop.exec();
|
|
|
|
|
}
|