1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 07:37:46 +00:00

SpiceAgent: Port to LibMain :^)

This commit is contained in:
Andreas Kling 2021-11-28 13:49:24 +01:00
parent 83056efc1a
commit 16746efcf8
2 changed files with 11 additions and 28 deletions

View file

@ -10,5 +10,5 @@ set(SOURCES
) )
serenity_bin(SpiceAgent) serenity_bin(SpiceAgent)
target_link_libraries(SpiceAgent LibGfx LibCore LibIPC) target_link_libraries(SpiceAgent LibGfx LibCore LibIPC LibMain)
add_dependencies(SpiceAgent Clipboard) add_dependencies(SpiceAgent Clipboard)

View file

@ -5,42 +5,25 @@
*/ */
#include "SpiceAgent.h" #include "SpiceAgent.h"
#include <AK/Format.h>
#include <LibC/fcntl.h> #include <LibC/fcntl.h>
#include <LibC/unistd.h> #include <LibCore/System.h>
#include <LibIPC/ServerConnection.h> #include <LibIPC/ServerConnection.h>
#include <LibMain/Main.h>
static constexpr auto SPICE_DEVICE = "/dev/hvc0p1"; static constexpr auto SPICE_DEVICE = "/dev/hvc0p1"sv;
int main() ErrorOr<int> serenity_main(Main::Arguments)
{ {
Core::EventLoop loop; Core::EventLoop loop;
if (pledge("unix rpath wpath stdio sendfd recvfd", nullptr) < 0) { TRY(Core::System::pledge("unix rpath wpath stdio sendfd recvfd", nullptr));
perror("pledge"); TRY(Core::System::unveil(SPICE_DEVICE, "rw"));
return 1; TRY(Core::System::unveil("/tmp/portal/clipboard", "rw"));
} TRY(Core::System::unveil(nullptr, nullptr));
if (unveil(SPICE_DEVICE, "rw") < 0) { int serial_port_fd = TRY(Core::System::open(SPICE_DEVICE, O_RDWR));
perror("unveil");
return 1;
}
if (unveil("/tmp/portal/clipboard", "rw") < 0) {
perror("unveil");
return 1;
}
if (unveil(nullptr, nullptr) < 0) {
perror("unveil");
return 1;
}
int serial_port_fd = open(SPICE_DEVICE, O_RDWR); auto conn = TRY(ClipboardServerConnection::try_create());
if (serial_port_fd < 0) {
dbgln("Couldn't open spice serial port!");
return 1;
}
auto conn = ClipboardServerConnection::construct();
auto agent = SpiceAgent(serial_port_fd, conn); auto agent = SpiceAgent(serial_port_fd, conn);
return loop.exec(); return loop.exec();