summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-11-22 16:12:40 +0100
committerAndreas Kling <kling@serenityos.org>2021-11-22 19:28:31 +0100
commite388782f6013cf9efcccade28f9fc7b1772d4d96 (patch)
treef4c952a9eda210fc8303bf235dcac82400c98691
parent3d34216b9a368f0c7ca66ab4d405cffdd62cee15 (diff)
downloadserenity-e388782f6013cf9efcccade28f9fc7b1772d4d96.zip
Terminal: Port to LibMain :^)
This simplifies a bunch of error handling and makes the main function quite a bit shorter. It will become shorter yet, as we get better at propagating errors. :^)
-rw-r--r--Userland/Applications/Terminal/CMakeLists.txt2
-rw-r--r--Userland/Applications/Terminal/main.cpp69
2 files changed, 18 insertions, 53 deletions
diff --git a/Userland/Applications/Terminal/CMakeLists.txt b/Userland/Applications/Terminal/CMakeLists.txt
index dc274cce98..37910af321 100644
--- a/Userland/Applications/Terminal/CMakeLists.txt
+++ b/Userland/Applications/Terminal/CMakeLists.txt
@@ -12,4 +12,4 @@ set(SOURCES
)
serenity_app(Terminal ICON app-terminal)
-target_link_libraries(Terminal LibGUI LibVT)
+target_link_libraries(Terminal LibGUI LibVT LibMain)
diff --git a/Userland/Applications/Terminal/main.cpp b/Userland/Applications/Terminal/main.cpp
index cf439f9bae..cf6bbf5d97 100644
--- a/Userland/Applications/Terminal/main.cpp
+++ b/Userland/Applications/Terminal/main.cpp
@@ -32,6 +32,8 @@
#include <LibGUI/Widget.h>
#include <LibGUI/Window.h>
#include <LibGfx/Palette.h>
+#include <LibMain/Main.h>
+#include <LibSystem/Wrappers.h>
#include <LibVT/TerminalWidget.h>
#include <assert.h>
#include <errno.h>
@@ -248,29 +250,20 @@ static RefPtr<GUI::Window> create_find_window(VT::TerminalWidget& terminal)
return window;
}
-int main(int argc, char** argv)
+ErrorOr<int> serenity_main(Main::Arguments arguments)
{
- if (pledge("stdio tty rpath cpath wpath recvfd sendfd proc exec unix sigaction", nullptr) < 0) {
- perror("pledge");
- return 1;
- }
+ TRY(System::pledge("stdio tty rpath cpath wpath recvfd sendfd proc exec unix sigaction", nullptr));
struct sigaction act;
memset(&act, 0, sizeof(act));
act.sa_flags = SA_NOCLDWAIT;
act.sa_handler = SIG_IGN;
- int rc = sigaction(SIGCHLD, &act, nullptr);
- if (rc < 0) {
- perror("sigaction");
- return 1;
- }
- auto app = GUI::Application::construct(argc, argv);
+ TRY(System::sigaction(SIGCHLD, &act, nullptr));
- if (pledge("stdio tty rpath cpath wpath recvfd sendfd proc exec unix", nullptr) < 0) {
- perror("pledge");
- return 1;
- }
+ auto app = GUI::Application::construct(arguments.argc, arguments.argv);
+
+ TRY(System::pledge("stdio tty rpath cpath wpath recvfd sendfd proc exec unix", nullptr));
Config::pledge_domains("Terminal");
@@ -281,7 +274,7 @@ int main(int argc, char** argv)
args_parser.add_option(command_to_execute, "Execute this command inside the terminal", nullptr, 'e', "command");
args_parser.add_option(keep_open, "Keep the terminal open after the command has finished executing", nullptr, 'k');
- args_parser.parse(argc, argv);
+ args_parser.parse(arguments.argc, arguments.argv);
if (keep_open && !command_to_execute) {
warnln("Option -k can only be used in combination with -e.");
@@ -429,42 +422,14 @@ int main(int argc, char** argv)
settings_window->close();
};
- if (unveil("/res", "r") < 0) {
- perror("unveil");
- return 1;
- }
-
- if (unveil("/bin", "r") < 0) {
- perror("unveil");
- return 1;
- }
-
- if (unveil("/bin/Terminal", "x") < 0) {
- perror("unveil");
- return 1;
- }
-
- if (unveil("/bin/utmpupdate", "x") < 0) {
- perror("unveil");
- return 1;
- }
-
- if (unveil("/etc/FileIconProvider.ini", "r") < 0) {
- perror("unveil");
- return 1;
- }
-
- if (unveil("/tmp/portal/launch", "rw") < 0) {
- perror("unveil");
- return 1;
- }
-
- if (unveil("/tmp/portal/config", "rw") < 0) {
- perror("unveil");
- return 1;
- }
-
- unveil(nullptr, nullptr);
+ TRY(System::unveil("/res", "r"));
+ TRY(System::unveil("/bin", "r"));
+ TRY(System::unveil("/bin/Terminal", "x"));
+ TRY(System::unveil("/bin/utmpupdate", "x"));
+ TRY(System::unveil("/etc/FileIconProvider.ini", "r"));
+ TRY(System::unveil("/tmp/portal/launch", "rw"));
+ TRY(System::unveil("/tmp/portal/config", "rw"));
+ TRY(System::unveil(nullptr, nullptr));
window->show();
int result = app->exec();