summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-11-22 23:20:52 +0100
committerAndreas Kling <kling@serenityos.org>2021-11-22 23:52:47 +0100
commit9cf874ef9a72988e6e909c0ce92848a8f96b1a63 (patch)
treebb9ad2b2e358c728d5c8a89ca6d7b25e2e8e0b33
parent97eb662e6203ff484fd9509706ddcdd89a425d67 (diff)
downloadserenity-9cf874ef9a72988e6e909c0ce92848a8f96b1a63.zip
WindowServer: Port to LibMain :^)
This simplifies some pledge(), unveil() and sigaction() calls.
-rw-r--r--Userland/Services/WindowServer/CMakeLists.txt2
-rw-r--r--Userland/Services/WindowServer/main.cpp61
2 files changed, 15 insertions, 48 deletions
diff --git a/Userland/Services/WindowServer/CMakeLists.txt b/Userland/Services/WindowServer/CMakeLists.txt
index b536a16ff5..154beb9ad8 100644
--- a/Userland/Services/WindowServer/CMakeLists.txt
+++ b/Userland/Services/WindowServer/CMakeLists.txt
@@ -39,5 +39,5 @@ set(SOURCES
)
serenity_bin(WindowServer)
-target_link_libraries(WindowServer LibCore LibGfx LibThreading LibIPC)
+target_link_libraries(WindowServer LibCore LibGfx LibThreading LibIPC LibMain)
serenity_install_headers(Services/WindowServer)
diff --git a/Userland/Services/WindowServer/main.cpp b/Userland/Services/WindowServer/main.cpp
index 94a7fd91cb..d4ff05dbc3 100644
--- a/Userland/Services/WindowServer/main.cpp
+++ b/Userland/Services/WindowServer/main.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
+ * Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@@ -14,47 +14,23 @@
#include <LibCore/File.h>
#include <LibGfx/Palette.h>
#include <LibGfx/SystemTheme.h>
+#include <LibMain/Main.h>
+#include <LibSystem/Wrappers.h>
#include <signal.h>
-#include <stdio.h>
#include <string.h>
-#include <unistd.h>
-int main(int, char**)
+ErrorOr<int> serenity_main(Main::Arguments)
{
- if (pledge("stdio video thread sendfd recvfd accept rpath wpath cpath unix proc sigaction", nullptr) < 0) {
- perror("pledge");
- return 1;
- }
-
- if (unveil("/res", "r") < 0) {
- perror("unveil /res");
- return 1;
- }
-
- if (unveil("/tmp", "cw") < 0) {
- perror("unveil /tmp cw");
- return 1;
- }
-
- if (unveil("/etc/WindowServer.ini", "rwc") < 0) {
- perror("unveil /etc/WindowServer.ini");
- return 1;
- }
+ TRY(System::pledge("stdio video thread sendfd recvfd accept rpath wpath cpath unix proc sigaction", nullptr));
+ TRY(System::unveil("/res", "r"));
+ TRY(System::unveil("/tmp", "cw"));
+ TRY(System::unveil("/etc/WindowServer.ini", "rwc"));
+ TRY(System::unveil("/dev", "rw"));
- if (unveil("/dev", "rw") < 0) {
- perror("unveil /dev rw");
- return 1;
- }
-
- struct sigaction act;
- memset(&act, 0, sizeof(act));
+ struct sigaction act = {};
act.sa_flags = SA_NOCLDWAIT;
act.sa_handler = SIG_IGN;
- int rc = sigaction(SIGCHLD, &act, nullptr);
- if (rc < 0) {
- perror("sigaction");
- return 1;
- }
+ TRY(System::sigaction(SIGCHLD, &act, nullptr));
auto wm_config = Core::ConfigFile::open("/etc/WindowServer.ini");
auto theme_name = wm_config->read_entry("Theme", "Name", "Default");
@@ -72,10 +48,7 @@ int main(int, char**)
WindowServer::EventLoop loop;
- if (pledge("stdio video thread sendfd recvfd accept rpath wpath cpath proc", nullptr) < 0) {
- perror("pledge");
- return 1;
- }
+ TRY(System::pledge("stdio video thread sendfd recvfd accept rpath wpath cpath proc", nullptr));
// First check which screens are explicitly configured
{
@@ -141,19 +114,13 @@ int main(int, char**)
auto am = WindowServer::AppletManager::construct();
auto mm = WindowServer::MenuManager::construct();
- if (unveil("/tmp", "") < 0) {
- perror("unveil /tmp");
- return 1;
- }
+ TRY(System::unveil("/tmp", ""));
// NOTE: Because we dynamically need to be able to open new /dev/fb*
// devices we can't really unveil all of /dev unless we have some
// other mechanism that can hand us file descriptors for these.
- if (unveil(nullptr, nullptr) < 0) {
- perror("unveil");
- return 1;
- }
+ TRY(System::unveil(nullptr, nullptr));
dbgln("Entering WindowServer main loop");
loop.exec();