main.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*
  2. * Copyright (c) 2020, Nicholas Hollett <niax@niax.co.uk>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include "ClientConnection.h"
  7. #include "Launcher.h"
  8. #include <LibCore/ConfigFile.h>
  9. #include <LibCore/EventLoop.h>
  10. #include <LibCore/LocalServer.h>
  11. #include <stdio.h>
  12. #include <unistd.h>
  13. int main([[maybe_unused]] int argc, [[maybe_unused]] char** argv)
  14. {
  15. Core::EventLoop event_loop;
  16. auto server = Core::LocalServer::construct();
  17. auto launcher = LaunchServer::Launcher();
  18. launcher.load_handlers();
  19. launcher.load_config(Core::ConfigFile::open_for_app("LaunchServer"));
  20. if (pledge("stdio accept rpath proc exec", nullptr) < 0) {
  21. perror("pledge");
  22. return 1;
  23. }
  24. bool ok = server->take_over_from_system_server();
  25. VERIFY(ok);
  26. server->on_ready_to_accept = [&] {
  27. auto client_socket = server->accept();
  28. if (!client_socket) {
  29. dbgln("LaunchServer: accept failed.");
  30. return;
  31. }
  32. static int s_next_client_id = 0;
  33. int client_id = ++s_next_client_id;
  34. IPC::new_client_connection<LaunchServer::ClientConnection>(client_socket.release_nonnull(), client_id);
  35. };
  36. return event_loop.exec();
  37. }