main.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <AK/OwnPtr.h>
  7. #include <LibCore/EventLoop.h>
  8. #include <LibCore/LocalServer.h>
  9. #include <LibCore/System.h>
  10. #include <LibIPC/SingleServer.h>
  11. #include <LibMain/Main.h>
  12. #include <LibTLS/Certificate.h>
  13. #include <RequestServer/ConnectionFromClient.h>
  14. #include <RequestServer/HttpProtocol.h>
  15. #include <RequestServer/HttpsProtocol.h>
  16. #include <signal.h>
  17. ErrorOr<int> serenity_main(Main::Arguments)
  18. {
  19. TRY(Core::System::pledge("stdio inet accept thread unix rpath sendfd recvfd sigaction"));
  20. #ifdef SIGINFO
  21. signal(SIGINFO, [](int) { RequestServer::ConnectionCache::dump_jobs(); });
  22. #endif
  23. TRY(Core::System::pledge("stdio inet accept thread unix rpath sendfd recvfd"));
  24. // Ensure the certificates are read out here.
  25. // FIXME: Allow specifying extra certificates on the command line, or in other configuration.
  26. [[maybe_unused]] auto& certs = DefaultRootCACertificates::the();
  27. Core::EventLoop event_loop;
  28. // FIXME: Establish a connection to LookupServer and then drop "unix"?
  29. TRY(Core::System::unveil("/tmp/portal/lookup", "rw"));
  30. TRY(Core::System::unveil("/etc/cacert.pem", "rw"));
  31. TRY(Core::System::unveil("/etc/timezone", "r"));
  32. TRY(Core::System::unveil(nullptr, nullptr));
  33. RequestServer::HttpProtocol::install();
  34. RequestServer::HttpsProtocol::install();
  35. auto client = TRY(IPC::take_over_accepted_client_from_system_server<RequestServer::ConnectionFromClient>());
  36. return event_loop.exec();
  37. }