Compare commits
2 Commits
ca5b4de2d8
...
75d0d12b71
Author | SHA1 | Date | |
---|---|---|---|
75d0d12b71 | |||
a7ff298852 |
@ -50,3 +50,4 @@ target_link_libraries(2048 PUBLIC ui)
|
|||||||
luna_app(clock.cpp clock)
|
luna_app(clock.cpp clock)
|
||||||
target_link_libraries(clock PUBLIC ui)
|
target_link_libraries(clock PUBLIC ui)
|
||||||
luna_app(startui.cpp startui)
|
luna_app(startui.cpp startui)
|
||||||
|
luna_app(launch.cpp launch)
|
||||||
|
153
apps/launch.cpp
Normal file
153
apps/launch.cpp
Normal file
@ -0,0 +1,153 @@
|
|||||||
|
/**
|
||||||
|
* @file launch.cpp
|
||||||
|
* @author apio (cloudapio.eu)
|
||||||
|
* @brief Background process that handles detached launching of apps.
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2024, the Luna authors.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <os/ArgumentParser.h>
|
||||||
|
#include <os/File.h>
|
||||||
|
#include <os/LocalServer.h>
|
||||||
|
#include <os/Process.h>
|
||||||
|
#include <os/Security.h>
|
||||||
|
#include <os/ipc/Launcher.h>
|
||||||
|
#include <signal.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <sys/poll.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
struct Client
|
||||||
|
{
|
||||||
|
os::LocalServer::Client conn;
|
||||||
|
u8 rpc_id { 0 };
|
||||||
|
bool rpc_in_progress { false };
|
||||||
|
|
||||||
|
Client(os::LocalServer::Client&& client) : conn(move(client)) {};
|
||||||
|
};
|
||||||
|
|
||||||
|
#define READ_MESSAGE(request) \
|
||||||
|
do { \
|
||||||
|
auto rc = client.conn.recv_typed(request); \
|
||||||
|
if (rc.has_error()) \
|
||||||
|
{ \
|
||||||
|
if (rc.error() == EAGAIN) \
|
||||||
|
{ \
|
||||||
|
client.rpc_in_progress = true; \
|
||||||
|
client.rpc_id = decltype(request)::ID; \
|
||||||
|
return {}; \
|
||||||
|
} \
|
||||||
|
if (rc.error() == EINTR) \
|
||||||
|
{ \
|
||||||
|
client.rpc_in_progress = true; \
|
||||||
|
client.rpc_id = decltype(request)::ID; \
|
||||||
|
return {}; \
|
||||||
|
} \
|
||||||
|
else \
|
||||||
|
return rc.release_error(); \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
Result<void> handle_launch_detached_message(Client& client)
|
||||||
|
{
|
||||||
|
os::Launcher::LaunchDetachedRequest request;
|
||||||
|
READ_MESSAGE(request);
|
||||||
|
|
||||||
|
auto path = COPY_IPC_STRING(request.command);
|
||||||
|
|
||||||
|
StringView args[] = { path.view() };
|
||||||
|
|
||||||
|
auto result = os::Process::spawn(args[0], { args, 1 }, false);
|
||||||
|
if (result.has_error()) os::IPC::send_error(client.conn, result.error());
|
||||||
|
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
Result<void> handle_ipc_message(Client& client, u8 id)
|
||||||
|
{
|
||||||
|
client.rpc_in_progress = false;
|
||||||
|
switch (id)
|
||||||
|
{
|
||||||
|
case os::Launcher::LAUNCH_DETACHED_ID: return handle_launch_detached_message(client);
|
||||||
|
default: os::eprintln("launch: Invalid IPC message from client!"); return err(EINVAL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static Result<void> handle_ipc(Client& client)
|
||||||
|
{
|
||||||
|
if (client.rpc_in_progress) return handle_ipc_message(client, client.rpc_id);
|
||||||
|
|
||||||
|
u8 id;
|
||||||
|
auto rc = client.conn.recv_typed(id);
|
||||||
|
if (rc.has_error())
|
||||||
|
{
|
||||||
|
if (rc.error() == EAGAIN) { return {}; }
|
||||||
|
if (rc.error() == EINTR) { return {}; }
|
||||||
|
else
|
||||||
|
return rc.release_error();
|
||||||
|
}
|
||||||
|
|
||||||
|
return handle_ipc_message(client, id);
|
||||||
|
}
|
||||||
|
|
||||||
|
void sigchld_handler(int)
|
||||||
|
{
|
||||||
|
os::Process::wait(os::Process::ANY_CHILD, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
Result<int> luna_main(int argc, char** argv)
|
||||||
|
{
|
||||||
|
TRY(os::Security::pledge("stdio wpath cpath unix proc exec", NULL));
|
||||||
|
|
||||||
|
StringView socket_path = "/tmp/launch.sock";
|
||||||
|
|
||||||
|
os::ArgumentParser parser;
|
||||||
|
parser.add_description("Background process that handles detached launching of apps."_sv);
|
||||||
|
parser.add_system_program_info("launch"_sv);
|
||||||
|
parser.parse(argc, argv);
|
||||||
|
|
||||||
|
signal(SIGCHLD, sigchld_handler);
|
||||||
|
|
||||||
|
auto server = TRY(os::LocalServer::create(socket_path, false));
|
||||||
|
TRY(server->listen(20));
|
||||||
|
|
||||||
|
Vector<OwnedPtr<Client>> clients;
|
||||||
|
Vector<struct pollfd> fds;
|
||||||
|
TRY(fds.try_append({ .fd = server->fd(), .events = POLLIN, .revents = 0 }));
|
||||||
|
|
||||||
|
TRY(os::Security::pledge("stdio unix proc exec", NULL));
|
||||||
|
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
for (auto& pfd : fds) { pfd.revents = 0; }
|
||||||
|
|
||||||
|
int rc = poll(fds.data(), fds.size(), 1000);
|
||||||
|
if (!rc) continue;
|
||||||
|
if (rc < 0 && errno != EINTR) { os::println("poll: error: %s", strerror(errno)); }
|
||||||
|
|
||||||
|
if (fds[0].revents & POLLIN)
|
||||||
|
{
|
||||||
|
auto client = TRY(server->accept());
|
||||||
|
os::println("launch: New client connected!");
|
||||||
|
TRY(fds.try_append({ .fd = client.fd(), .events = POLLIN, .revents = 0 }));
|
||||||
|
OwnedPtr<Client> c = TRY(adopt_owned_if_nonnull(new Client(move(client))));
|
||||||
|
TRY(clients.try_append(move(c)));
|
||||||
|
}
|
||||||
|
for (usize i = 0; i < clients.size(); i++)
|
||||||
|
{
|
||||||
|
if (fds[i + 1].revents & POLLIN) handle_ipc(*clients[i]);
|
||||||
|
if (fds[i + 1].revents & POLLHUP)
|
||||||
|
{
|
||||||
|
os::println("launch: Client %d disconnected", i);
|
||||||
|
fds.remove_at(i + 1);
|
||||||
|
auto client = clients.remove_at(i);
|
||||||
|
client->conn.disconnect();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -119,6 +119,9 @@ Result<int> luna_main(int argc, char** argv)
|
|||||||
setenv("SHELL", pw->pw_shell, 1);
|
setenv("SHELL", pw->pw_shell, 1);
|
||||||
|
|
||||||
// Next, start the required UI components.
|
// Next, start the required UI components.
|
||||||
|
StringView launch_command[] = { "/usr/bin/launch" };
|
||||||
|
TRY(spawn_process_as_user(Slice<StringView>(launch_command, 1), pw->pw_uid, pw->pw_gid, groups.slice()));
|
||||||
|
|
||||||
StringView taskbar_command[] = { "/usr/bin/taskbar" };
|
StringView taskbar_command[] = { "/usr/bin/taskbar" };
|
||||||
TRY(spawn_process_as_user(Slice<StringView>(taskbar_command, 1), pw->pw_uid, pw->pw_gid, system_groups.slice()));
|
TRY(spawn_process_as_user(Slice<StringView>(taskbar_command, 1), pw->pw_uid, pw->pw_gid, system_groups.slice()));
|
||||||
|
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
#include <os/File.h>
|
#include <os/File.h>
|
||||||
|
#include <os/IPC.h>
|
||||||
|
#include <os/LocalClient.h>
|
||||||
#include <os/Process.h>
|
#include <os/Process.h>
|
||||||
|
#include <os/ipc/Launcher.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
#include <ui/App.h>
|
#include <ui/App.h>
|
||||||
@ -10,12 +13,14 @@
|
|||||||
|
|
||||||
static constexpr ui::Color TASKBAR_COLOR = ui::Color::from_rgb(83, 83, 83);
|
static constexpr ui::Color TASKBAR_COLOR = ui::Color::from_rgb(83, 83, 83);
|
||||||
|
|
||||||
|
static OwnedPtr<os::LocalClient> launcher_client;
|
||||||
|
|
||||||
void sigchld_handler(int)
|
void sigchld_handler(int)
|
||||||
{
|
{
|
||||||
wait(nullptr);
|
wait(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
Result<void> create_widget_group_for_app(ui::HorizontalLayout& layout, Slice<StringView> args, StringView icon)
|
Result<void> create_widget_group_for_app(ui::HorizontalLayout& layout, StringView path, StringView icon)
|
||||||
{
|
{
|
||||||
auto* button = new (std::nothrow) ui::Button({ 0, 0, 50, 50 });
|
auto* button = new (std::nothrow) ui::Button({ 0, 0, 50, 50 });
|
||||||
if (!button) return err(ENOMEM);
|
if (!button) return err(ENOMEM);
|
||||||
@ -25,7 +30,11 @@ Result<void> create_widget_group_for_app(ui::HorizontalLayout& layout, Slice<Str
|
|||||||
ui::Container({ 0, 0, 50, 50 }, ui::VerticalAlignment::Center, ui::HorizontalAlignment::Center);
|
ui::Container({ 0, 0, 50, 50 }, ui::VerticalAlignment::Center, ui::HorizontalAlignment::Center);
|
||||||
if (!container) return err(ENOMEM);
|
if (!container) return err(ENOMEM);
|
||||||
button->set_widget(*container);
|
button->set_widget(*container);
|
||||||
button->set_action([=] { os::Process::spawn(args[0], args, false); });
|
button->set_action([=] {
|
||||||
|
os::Launcher::LaunchDetachedRequest request;
|
||||||
|
SET_IPC_STRING(request.command, path.chars());
|
||||||
|
os::IPC::send_async(*launcher_client, request);
|
||||||
|
});
|
||||||
|
|
||||||
auto image = TRY(ui::ImageWidget::load(icon));
|
auto image = TRY(ui::ImageWidget::load(icon));
|
||||||
container->set_widget(*image);
|
container->set_widget(*image);
|
||||||
@ -38,10 +47,12 @@ Result<void> create_widget_group_for_app(ui::HorizontalLayout& layout, Slice<Str
|
|||||||
Result<int> luna_main(int, char**)
|
Result<int> luna_main(int, char**)
|
||||||
{
|
{
|
||||||
ui::App app;
|
ui::App app;
|
||||||
TRY(app.init());
|
TRY(app.init("/tmp/wsys.sock"));
|
||||||
|
|
||||||
TRY(os::EventLoop::the().register_signal_handler(SIGCHLD, sigchld_handler));
|
TRY(os::EventLoop::the().register_signal_handler(SIGCHLD, sigchld_handler));
|
||||||
|
|
||||||
|
launcher_client = TRY(os::LocalClient::connect("/tmp/launch.sock", false));
|
||||||
|
|
||||||
ui::Rect screen = app.screen_rect();
|
ui::Rect screen = app.screen_rect();
|
||||||
|
|
||||||
ui::Rect bar = ui::Rect { ui::Point { 0, screen.height - 50 }, screen.width, 50 };
|
ui::Rect bar = ui::Rect { ui::Point { 0, screen.height - 50 }, screen.width, 50 };
|
||||||
@ -54,17 +65,10 @@ Result<int> luna_main(int, char**)
|
|||||||
ui::HorizontalLayout layout(ui::Margins { 0, 0, 0, 0 }, ui::AdjustHeight::Yes, ui::AdjustWidth::No);
|
ui::HorizontalLayout layout(ui::Margins { 0, 0, 0, 0 }, ui::AdjustHeight::Yes, ui::AdjustWidth::No);
|
||||||
window->set_main_widget(layout);
|
window->set_main_widget(layout);
|
||||||
|
|
||||||
StringView terminal_command[] = { "/usr/bin/terminal" };
|
TRY(create_widget_group_for_app(layout, "/usr/bin/terminal", "/usr/share/icons/32x32/app-terminal.tga"));
|
||||||
TRY(create_widget_group_for_app(layout, { terminal_command, 1 }, "/usr/share/icons/32x32/app-terminal.tga"));
|
TRY(create_widget_group_for_app(layout, "/usr/bin/about", "/usr/share/icons/32x32/app-about.tga"));
|
||||||
|
TRY(create_widget_group_for_app(layout, "/usr/bin/gol", "/usr/share/icons/32x32/app-gol.tga"));
|
||||||
StringView about_command[] = { "/usr/bin/about" };
|
TRY(create_widget_group_for_app(layout, "/usr/bin/clock", "/usr/share/icons/32x32/app-clock.tga"));
|
||||||
TRY(create_widget_group_for_app(layout, { about_command, 1 }, "/usr/share/icons/32x32/app-about.tga"));
|
|
||||||
|
|
||||||
StringView gol_command[] = { "/usr/bin/gol" };
|
|
||||||
TRY(create_widget_group_for_app(layout, { gol_command, 1 }, "/usr/share/icons/32x32/app-gol.tga"));
|
|
||||||
|
|
||||||
StringView clock_command[] = { "/usr/bin/clock" };
|
|
||||||
TRY(create_widget_group_for_app(layout, { clock_command, 1 }, "/usr/share/icons/32x32/app-clock.tga"));
|
|
||||||
|
|
||||||
return app.run();
|
return app.run();
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
root:!:0:
|
root:!:0:
|
||||||
users:!:1:selene
|
users:!:1:selene
|
||||||
wind:!:2:selene
|
wind:!:2:selene
|
||||||
|
wsys:!:3:
|
||||||
selene:!:1000:
|
selene:!:1000:
|
||||||
|
30
libos/include/os/ipc/Launcher.h
Normal file
30
libos/include/os/ipc/Launcher.h
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
/**
|
||||||
|
* @file ipc/Launcher.h
|
||||||
|
* @author apio (cloudapio.eu)
|
||||||
|
* @brief IPC message definitions for UI messages sent to the launch server.
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2024, the Luna authors.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include <os/IPC.h>
|
||||||
|
|
||||||
|
namespace os
|
||||||
|
{
|
||||||
|
namespace Launcher
|
||||||
|
{
|
||||||
|
enum ServerMessages : u8
|
||||||
|
{
|
||||||
|
IPC_ENUM_SERVER(launch),
|
||||||
|
LAUNCH_DETACHED_ID,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct LaunchDetachedRequest
|
||||||
|
{
|
||||||
|
static constexpr u8 ID = LAUNCH_DETACHED_ID;
|
||||||
|
|
||||||
|
IPC_STRING(command);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
@ -6,12 +6,13 @@ struct Client
|
|||||||
{
|
{
|
||||||
os::LocalServer::Client conn;
|
os::LocalServer::Client conn;
|
||||||
Vector<Window*> windows;
|
Vector<Window*> windows;
|
||||||
|
const bool privileged { false };
|
||||||
bool rpc_in_progress { false };
|
bool rpc_in_progress { false };
|
||||||
u8 rpc_id { 0 };
|
u8 rpc_id { 0 };
|
||||||
|
|
||||||
Client(os::LocalServer::Client&& client)
|
Client(os::LocalServer::Client&& client, bool priv)
|
||||||
#ifdef CLIENT_IMPLEMENTATION
|
#ifdef CLIENT_IMPLEMENTATION
|
||||||
: conn(move(client)), windows() {}
|
: conn(move(client)), windows(), privileged(priv) {}
|
||||||
#else
|
#else
|
||||||
;
|
;
|
||||||
#endif
|
#endif
|
||||||
|
@ -6,17 +6,14 @@
|
|||||||
#include "Screen.h"
|
#include "Screen.h"
|
||||||
#include "Window.h"
|
#include "Window.h"
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <grp.h>
|
|
||||||
#include <moon/Keyboard.h>
|
#include <moon/Keyboard.h>
|
||||||
#include <os/ArgumentParser.h>
|
#include <os/ArgumentParser.h>
|
||||||
#include <os/File.h>
|
#include <os/File.h>
|
||||||
#include <os/LocalServer.h>
|
#include <os/LocalServer.h>
|
||||||
#include <os/Process.h>
|
#include <os/Process.h>
|
||||||
#include <os/Security.h>
|
#include <os/Security.h>
|
||||||
#include <pwd.h>
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/ioctl.h>
|
|
||||||
#include <sys/poll.h>
|
#include <sys/poll.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
@ -24,6 +21,7 @@
|
|||||||
|
|
||||||
static constexpr uid_t WIND_USER_ID = 2;
|
static constexpr uid_t WIND_USER_ID = 2;
|
||||||
static constexpr gid_t WIND_GROUP_ID = 2;
|
static constexpr gid_t WIND_GROUP_ID = 2;
|
||||||
|
static constexpr gid_t WSYS_GROUP_ID = 3;
|
||||||
|
|
||||||
static void debug(const Vector<OwnedPtr<Client>>& clients)
|
static void debug(const Vector<OwnedPtr<Client>>& clients)
|
||||||
{
|
{
|
||||||
@ -63,11 +61,14 @@ Result<int> luna_main(int argc, char** argv)
|
|||||||
TRY(os::Security::pledge("stdio rpath wpath cpath unix proc exec tty id", NULL));
|
TRY(os::Security::pledge("stdio rpath wpath cpath unix proc exec tty id", NULL));
|
||||||
|
|
||||||
StringView socket_path = "/tmp/wind.sock";
|
StringView socket_path = "/tmp/wind.sock";
|
||||||
|
StringView system_socket_path = "/tmp/wsys.sock";
|
||||||
|
|
||||||
os::ArgumentParser parser;
|
os::ArgumentParser parser;
|
||||||
parser.add_description("The display server for Luna's graphical user interface."_sv);
|
parser.add_description("The display server for Luna's graphical user interface."_sv);
|
||||||
parser.add_system_program_info("wind"_sv);
|
parser.add_system_program_info("wind"_sv);
|
||||||
parser.add_value_argument(socket_path, 's', "socket"_sv, "the path for the local IPC socket"_sv);
|
parser.add_value_argument(socket_path, 's', "socket"_sv, "the path for the local IPC socket"_sv);
|
||||||
|
parser.add_value_argument(system_socket_path, ' ', "system-socket"_sv,
|
||||||
|
"the path for the system IPC socket, for privileged clients"_sv);
|
||||||
parser.parse(argc, argv);
|
parser.parse(argc, argv);
|
||||||
|
|
||||||
if (geteuid() != 0)
|
if (geteuid() != 0)
|
||||||
@ -90,10 +91,24 @@ Result<int> luna_main(int argc, char** argv)
|
|||||||
|
|
||||||
Mouse mouse_pointer { screen.canvas() };
|
Mouse mouse_pointer { screen.canvas() };
|
||||||
|
|
||||||
|
umask(0002);
|
||||||
|
|
||||||
|
// Set permissions to wind:wsys temporarily, to create /tmp/wsys.sock with those privileges.
|
||||||
|
setegid(WSYS_GROUP_ID);
|
||||||
|
seteuid(WIND_USER_ID);
|
||||||
|
|
||||||
|
auto system_server = TRY(os::LocalServer::create(system_socket_path, false));
|
||||||
|
TRY(system_server->listen(20));
|
||||||
|
|
||||||
|
seteuid(0);
|
||||||
|
|
||||||
// Opened all necessary files as root, drop privileges now.
|
// Opened all necessary files as root, drop privileges now.
|
||||||
setgid(WIND_GROUP_ID);
|
setgid(WIND_GROUP_ID);
|
||||||
setuid(WIND_USER_ID);
|
setuid(WIND_USER_ID);
|
||||||
|
|
||||||
|
auto server = TRY(os::LocalServer::create(socket_path, false));
|
||||||
|
TRY(server->listen(20));
|
||||||
|
|
||||||
int fd = open("/dev/null", O_RDONLY);
|
int fd = open("/dev/null", O_RDONLY);
|
||||||
if (fd >= 0)
|
if (fd >= 0)
|
||||||
{
|
{
|
||||||
@ -101,11 +116,6 @@ Result<int> luna_main(int argc, char** argv)
|
|||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
umask(0002);
|
|
||||||
|
|
||||||
auto server = TRY(os::LocalServer::create(socket_path, false));
|
|
||||||
TRY(server->listen(20));
|
|
||||||
|
|
||||||
ui::Color background = ui::Color::from_rgb(0x10, 0x10, 0x10);
|
ui::Color background = ui::Color::from_rgb(0x10, 0x10, 0x10);
|
||||||
|
|
||||||
Vector<OwnedPtr<Client>> clients;
|
Vector<OwnedPtr<Client>> clients;
|
||||||
@ -113,6 +123,7 @@ Result<int> luna_main(int argc, char** argv)
|
|||||||
TRY(fds.try_append({ .fd = mouse->fd(), .events = POLLIN, .revents = 0 }));
|
TRY(fds.try_append({ .fd = mouse->fd(), .events = POLLIN, .revents = 0 }));
|
||||||
TRY(fds.try_append({ .fd = keyboard->fd(), .events = POLLIN, .revents = 0 }));
|
TRY(fds.try_append({ .fd = keyboard->fd(), .events = POLLIN, .revents = 0 }));
|
||||||
TRY(fds.try_append({ .fd = server->fd(), .events = POLLIN, .revents = 0 }));
|
TRY(fds.try_append({ .fd = server->fd(), .events = POLLIN, .revents = 0 }));
|
||||||
|
TRY(fds.try_append({ .fd = system_server->fd(), .events = POLLIN, .revents = 0 }));
|
||||||
|
|
||||||
TRY(os::Security::pledge("stdio rpath wpath cpath unix proc exec", NULL));
|
TRY(os::Security::pledge("stdio rpath wpath cpath unix proc exec", NULL));
|
||||||
|
|
||||||
@ -148,13 +159,29 @@ Result<int> luna_main(int argc, char** argv)
|
|||||||
os::IPC::send_async(window->client->conn, request);
|
os::IPC::send_async(window->client->conn, request);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (fds[2].revents & POLLIN)
|
||||||
|
{
|
||||||
|
auto client = TRY(server->accept());
|
||||||
|
os::println("wind: New client connected!");
|
||||||
|
TRY(fds.try_append({ .fd = client.fd(), .events = POLLIN, .revents = 0 }));
|
||||||
|
OwnedPtr<Client> c = TRY(adopt_owned_if_nonnull(new Client(move(client), false)));
|
||||||
|
TRY(clients.try_append(move(c)));
|
||||||
|
}
|
||||||
|
if (fds[3].revents & POLLIN)
|
||||||
|
{
|
||||||
|
auto client = TRY(system_server->accept());
|
||||||
|
os::println("wind: New privileged client connected!");
|
||||||
|
TRY(fds.try_append({ .fd = client.fd(), .events = POLLIN, .revents = 0 }));
|
||||||
|
OwnedPtr<Client> c = TRY(adopt_owned_if_nonnull(new Client(move(client), true)));
|
||||||
|
TRY(clients.try_append(move(c)));
|
||||||
|
}
|
||||||
for (usize i = 0; i < clients.size(); i++)
|
for (usize i = 0; i < clients.size(); i++)
|
||||||
{
|
{
|
||||||
if (fds[i + 3].revents & POLLIN) wind::handle_ipc(*clients[i]);
|
if (fds[i + 4].revents & POLLIN) wind::handle_ipc(*clients[i]);
|
||||||
if (fds[i + 3].revents & POLLHUP)
|
if (fds[i + 4].revents & POLLHUP)
|
||||||
{
|
{
|
||||||
os::println("wind: Client %d disconnected", i);
|
os::println("wind: Client %d disconnected", i);
|
||||||
fds.remove_at(i + 3);
|
fds.remove_at(i + 4);
|
||||||
auto client = clients.remove_at(i);
|
auto client = clients.remove_at(i);
|
||||||
client->conn.disconnect();
|
client->conn.disconnect();
|
||||||
for (auto& window : client->windows)
|
for (auto& window : client->windows)
|
||||||
@ -168,13 +195,5 @@ Result<int> luna_main(int argc, char** argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (fds[2].revents & POLLIN)
|
|
||||||
{
|
|
||||||
auto client = TRY(server->accept());
|
|
||||||
os::println("wind: New client connected!");
|
|
||||||
TRY(fds.try_append({ .fd = client.fd(), .events = POLLIN, .revents = 0 }));
|
|
||||||
OwnedPtr<Client> c = TRY(adopt_owned_if_nonnull(new Client(move(client))));
|
|
||||||
TRY(clients.try_append(move(c)));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user