1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-18 15:25:08 +00:00
serenity/Applications/TextEditor/main.cpp
Andreas Kling 26a31c7efb Kernel: Add "accept" pledge promise for accepting incoming connections
This patch adds a new "accept" promise that allows you to call accept()
on an already listening socket. This lets programs set up a socket for
for listening and then dropping "inet" and/or "unix" so that only
incoming (and existing) connections are allowed from that point on.
No new outgoing connections or listening server sockets can be created.

In addition to accept() it also allows getsockopt() with SOL_SOCKET
and SO_PEERCRED, which is used to find the PID/UID/GID of the socket
peer. This is used by our IPC library when creating shared buffers that
should only be accessible to a specific peer process.

This allows us to drop "unix" in WindowServer and LookupServer. :^)

It also makes the debugging/introspection RPC sockets in CEventLoop
based programs work again.
2020-01-17 11:19:06 +01:00

41 lines
1.1 KiB
C++

#include "TextEditorWidget.h"
#include <LibDraw/PNGLoader.h>
#include <stdio.h>
int main(int argc, char** argv)
{
if (pledge("stdio rpath accept cpath wpath shared_buffer unix fattr", nullptr) < 0) {
perror("pledge");
return 1;
}
GApplication app(argc, argv);
if (pledge("stdio rpath accept cpath wpath shared_buffer", nullptr) < 0) {
perror("pledge");
return 1;
}
auto window = GWindow::construct();
window->set_title("Text Editor");
window->set_rect(20, 200, 640, 400);
auto text_widget = TextEditorWidget::construct();
window->set_main_widget(text_widget);
text_widget->editor().set_focus(true);
window->on_close_request = [&]() -> GWindow::CloseRequestDecision {
if (text_widget->request_close())
return GWindow::CloseRequestDecision::Close;
return GWindow::CloseRequestDecision::StayOpen;
};
if (argc >= 2)
text_widget->open_sesame(argv[1]);
window->show();
window->set_icon(load_png("/res/icons/TextEditor16.png"));
return app.exec();
}