mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 00:47:45 +00:00
top: Port to LibMain :^)
This commit is contained in:
parent
e399835466
commit
cac3f3c81f
2 changed files with 11 additions and 24 deletions
|
@ -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-fuzz LibCore LibGemini LibGfx LibHTTP LibIPC LibJS LibMarkdown LibShell)
|
||||||
target_link_libraries(test-imap LibIMAP)
|
target_link_libraries(test-imap LibIMAP)
|
||||||
target_link_libraries(test-pthread LibThreading)
|
target_link_libraries(test-pthread LibThreading)
|
||||||
|
target_link_libraries(top LibMain)
|
||||||
target_link_libraries(truncate LibMain)
|
target_link_libraries(truncate LibMain)
|
||||||
target_link_libraries(tt LibPthread)
|
target_link_libraries(tt LibPthread)
|
||||||
target_link_libraries(unzip LibArchive LibCompress)
|
target_link_libraries(unzip LibArchive LibCompress)
|
||||||
|
|
|
@ -12,6 +12,8 @@
|
||||||
#include <AK/Vector.h>
|
#include <AK/Vector.h>
|
||||||
#include <LibCore/ArgsParser.h>
|
#include <LibCore/ArgsParser.h>
|
||||||
#include <LibCore/ProcessStatisticsReader.h>
|
#include <LibCore/ProcessStatisticsReader.h>
|
||||||
|
#include <LibCore/System.h>
|
||||||
|
#include <LibMain/Main.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -133,7 +135,7 @@ static Snapshot get_snapshot()
|
||||||
static bool g_window_size_changed = true;
|
static bool g_window_size_changed = true;
|
||||||
static struct winsize g_window_size;
|
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 {
|
Core::ArgsParser::Option sort_by_option {
|
||||||
true,
|
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.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(top_option.delay_time, "Delay time interval in seconds", "delay-time", 'd', nullptr);
|
||||||
args_parser.add_option(move(sort_by_option));
|
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) {
|
TRY(Core::System::pledge("stdio rpath tty sigaction"));
|
||||||
perror("pledge");
|
TRY(Core::System::unveil("/proc/all", "r"));
|
||||||
return 1;
|
TRY(Core::System::unveil("/etc/passwd", "r"));
|
||||||
}
|
|
||||||
|
|
||||||
if (unveil("/proc/all", "r") < 0) {
|
|
||||||
perror("unveil");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (unveil("/etc/passwd", "r") < 0) {
|
|
||||||
perror("unveil");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
unveil(nullptr, nullptr);
|
unveil(nullptr, nullptr);
|
||||||
|
|
||||||
signal(SIGWINCH, [](int) {
|
signal(SIGWINCH, [](int) {
|
||||||
g_window_size_changed = true;
|
g_window_size_changed = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (pledge("stdio rpath tty", nullptr) < 0) {
|
TRY(Core::System::pledge("stdio rpath tty"));
|
||||||
perror("pledge");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
TopOption top_option;
|
TopOption top_option;
|
||||||
parse_args(argc, argv, top_option);
|
parse_args(arguments, top_option);
|
||||||
|
|
||||||
Vector<ThreadData*> threads;
|
Vector<ThreadData*> threads;
|
||||||
auto prev = get_snapshot();
|
auto prev = get_snapshot();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue