main.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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/LocalServer.h>
  12. #include <LibCore/System.h>
  13. #include <LibIPC/ClientConnection.h>
  14. #include <LibMain/Main.h>
  15. #include <unistd.h>
  16. static ErrorOr<int> mode_server();
  17. ErrorOr<int> serenity_main(Main::Arguments arguments)
  18. {
  19. bool tests = false;
  20. Core::ArgsParser parser;
  21. parser.add_option(tests, "Run tests", "tests", 't');
  22. parser.parse(arguments);
  23. if (tests)
  24. return run_tests();
  25. return mode_server();
  26. }
  27. ErrorOr<int> mode_server()
  28. {
  29. Core::EventLoop event_loop;
  30. TRY(Core::System::pledge("stdio unix recvfd rpath ", nullptr));
  31. auto socket = Core::LocalSocket::take_over_accepted_socket_from_system_server();
  32. IPC::new_client_connection<LanguageServers::Cpp::ClientConnection>(socket.release_nonnull(), 1);
  33. TRY(Core::System::pledge("stdio recvfd rpath", nullptr));
  34. TRY(Core::System::unveil("/usr/include", "r"));
  35. // unveil will be sealed later, when we know the project's root path.
  36. return event_loop.exec();
  37. }