main.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * Copyright (c) 2021, Itamar S. <itamar8910@gmail.com>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include "ClientConnection.h"
  7. #include "Tests.h"
  8. #include <AK/LexicalPath.h>
  9. #include <LibCore/ArgsParser.h>
  10. #include <LibCore/EventLoop.h>
  11. #include <LibCore/File.h>
  12. #include <LibCore/LocalServer.h>
  13. #include <LibIPC/ClientConnection.h>
  14. #include <sys/stat.h>
  15. #include <unistd.h>
  16. static int mode_server();
  17. int main(int argc, char** argv)
  18. {
  19. bool tests = false;
  20. Core::ArgsParser parser;
  21. parser.add_option(tests, "Run tests", "tests", 't');
  22. parser.parse(argc, argv);
  23. if (tests) {
  24. return run_tests();
  25. }
  26. return mode_server();
  27. }
  28. int mode_server()
  29. {
  30. Core::EventLoop event_loop;
  31. if (pledge("stdio unix recvfd rpath ", nullptr) < 0) {
  32. perror("pledge");
  33. return 1;
  34. }
  35. auto socket = Core::LocalSocket::take_over_accepted_socket_from_system_server();
  36. IPC::new_client_connection<LanguageServers::Cpp::ClientConnection>(socket.release_nonnull(), 1);
  37. if (pledge("stdio recvfd rpath", nullptr) < 0) {
  38. perror("pledge");
  39. return 1;
  40. }
  41. if (unveil("/usr/include", "r") < 0)
  42. perror("unveil");
  43. // unveil will be sealed later, when we know the project's root path.
  44. return event_loop.exec();
  45. }