summaryrefslogtreecommitdiff
path: root/Userland/Utilities
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-11-29 19:39:24 +0100
committerAndreas Kling <kling@serenityos.org>2021-11-30 23:34:40 +0100
commitcac3f3c81f60cbc94bae380fbf25222340fa4477 (patch)
tree8c6fe9ceb00332755a6b5c2c71d6decee2d4b7eb /Userland/Utilities
parente399835466fb364572ab27ef6947f1a11c674549 (diff)
downloadserenity-cac3f3c81f60cbc94bae380fbf25222340fa4477.zip
top: Port to LibMain :^)
Diffstat (limited to 'Userland/Utilities')
-rw-r--r--Userland/Utilities/CMakeLists.txt1
-rw-r--r--Userland/Utilities/top.cpp34
2 files changed, 11 insertions, 24 deletions
diff --git a/Userland/Utilities/CMakeLists.txt b/Userland/Utilities/CMakeLists.txt
index 8609e17ed4..c32930dad9 100644
--- a/Userland/Utilities/CMakeLists.txt
+++ b/Userland/Utilities/CMakeLists.txt
@@ -110,6 +110,7 @@ target_link_libraries(test-crypto LibCrypto LibTLS LibLine)
target_link_libraries(test-fuzz LibCore LibGemini LibGfx LibHTTP LibIPC LibJS LibMarkdown LibShell)
target_link_libraries(test-imap LibIMAP)
target_link_libraries(test-pthread LibThreading)
+target_link_libraries(top LibMain)
target_link_libraries(truncate LibMain)
target_link_libraries(tt LibPthread)
target_link_libraries(unzip LibArchive LibCompress)
diff --git a/Userland/Utilities/top.cpp b/Userland/Utilities/top.cpp
index 8630deed19..ab2fb74363 100644
--- a/Userland/Utilities/top.cpp
+++ b/Userland/Utilities/top.cpp
@@ -12,6 +12,8 @@
#include <AK/Vector.h>
#include <LibCore/ArgsParser.h>
#include <LibCore/ProcessStatisticsReader.h>
+#include <LibCore/System.h>
+#include <LibMain/Main.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
@@ -133,7 +135,7 @@ static Snapshot get_snapshot()
static bool g_window_size_changed = true;
static struct winsize g_window_size;
-static void parse_args(int argc, char** argv, TopOption& top_option)
+static void parse_args(Main::Arguments arguments, TopOption& top_option)
{
Core::ArgsParser::Option sort_by_option {
true,
@@ -172,39 +174,23 @@ static void parse_args(int argc, char** argv, TopOption& top_option)
args_parser.set_general_help("Display information about processes");
args_parser.add_option(top_option.delay_time, "Delay time interval in seconds", "delay-time", 'd', nullptr);
args_parser.add_option(move(sort_by_option));
- args_parser.parse(argc, argv);
+ args_parser.parse(arguments);
}
-int main(int argc, char** argv)
+ErrorOr<int> serenity_main(Main::Arguments arguments)
{
- if (pledge("stdio rpath tty sigaction ", nullptr) < 0) {
- perror("pledge");
- return 1;
- }
-
- if (unveil("/proc/all", "r") < 0) {
- perror("unveil");
- return 1;
- }
-
- if (unveil("/etc/passwd", "r") < 0) {
- perror("unveil");
- return 1;
- }
-
+ TRY(Core::System::pledge("stdio rpath tty sigaction"));
+ TRY(Core::System::unveil("/proc/all", "r"));
+ TRY(Core::System::unveil("/etc/passwd", "r"));
unveil(nullptr, nullptr);
signal(SIGWINCH, [](int) {
g_window_size_changed = true;
});
- if (pledge("stdio rpath tty", nullptr) < 0) {
- perror("pledge");
- return 1;
- }
-
+ TRY(Core::System::pledge("stdio rpath tty"));
TopOption top_option;
- parse_args(argc, argv, top_option);
+ parse_args(arguments, top_option);
Vector<ThreadData*> threads;
auto prev = get_snapshot();