2020-09-20 20:55:36 +03:00
|
|
|
/*
|
2021-02-06 15:58:02 +02:00
|
|
|
* Copyright (c) 2021, Itamar S. <itamar8910@gmail.com>
|
2020-09-20 20:55:36 +03:00
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-09-20 20:55:36 +03:00
|
|
|
*/
|
|
|
|
|
|
2021-01-31 15:10:45 +01:00
|
|
|
#include "ClientConnection.h"
|
2021-05-12 20:36:00 +03:00
|
|
|
#include "Tests.h"
|
2020-09-28 16:37:37 +03:00
|
|
|
#include <AK/LexicalPath.h>
|
2021-05-12 20:36:00 +03:00
|
|
|
#include <LibCore/ArgsParser.h>
|
2020-09-28 16:37:37 +03:00
|
|
|
#include <LibCore/EventLoop.h>
|
|
|
|
|
#include <LibCore/File.h>
|
|
|
|
|
#include <LibCore/LocalServer.h>
|
|
|
|
|
#include <LibIPC/ClientConnection.h>
|
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
#include <unistd.h>
|
2020-09-20 20:55:36 +03:00
|
|
|
|
2021-05-12 20:36:00 +03:00
|
|
|
static int mode_server();
|
|
|
|
|
|
|
|
|
|
int main(int argc, char** argv)
|
|
|
|
|
{
|
|
|
|
|
bool tests = false;
|
|
|
|
|
|
|
|
|
|
Core::ArgsParser parser;
|
|
|
|
|
parser.add_option(tests, "Run tests", "tests", 't');
|
|
|
|
|
parser.parse(argc, argv);
|
|
|
|
|
|
|
|
|
|
if (tests) {
|
|
|
|
|
return run_tests();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return mode_server();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int mode_server()
|
2020-09-28 16:37:37 +03:00
|
|
|
{
|
|
|
|
|
Core::EventLoop event_loop;
|
2021-02-06 15:58:02 +02:00
|
|
|
if (pledge("stdio unix recvfd rpath ", nullptr) < 0) {
|
2020-09-28 16:37:37 +03:00
|
|
|
perror("pledge");
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
2020-09-20 20:55:36 +03:00
|
|
|
|
2020-09-28 16:37:37 +03:00
|
|
|
auto socket = Core::LocalSocket::take_over_accepted_socket_from_system_server();
|
|
|
|
|
IPC::new_client_connection<LanguageServers::Cpp::ClientConnection>(socket.release_nonnull(), 1);
|
2021-02-06 15:58:02 +02:00
|
|
|
if (pledge("stdio recvfd rpath", nullptr) < 0) {
|
2020-09-28 16:37:37 +03:00
|
|
|
perror("pledge");
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
2021-02-06 15:58:02 +02:00
|
|
|
|
2021-06-11 19:54:42 +02:00
|
|
|
if (unveil("/usr/include", "r") < 0) {
|
2020-11-21 22:12:37 +03:00
|
|
|
perror("unveil");
|
2021-06-11 19:54:42 +02:00
|
|
|
return 1;
|
|
|
|
|
}
|
2021-02-06 15:58:02 +02:00
|
|
|
|
|
|
|
|
// unveil will be sealed later, when we know the project's root path.
|
2020-09-28 16:37:37 +03:00
|
|
|
return event_loop.exec();
|
|
|
|
|
}
|