From 8b5c0e8e71264a0b3aef3c0d3bd493efc2852471 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Tue, 23 Nov 2021 15:33:49 +0100 Subject: [PATCH] pmap: Port to LibMain :^) --- Userland/Utilities/CMakeLists.txt | 1 + Userland/Utilities/pmap.cpp | 31 +++++++++---------------------- 2 files changed, 10 insertions(+), 22 deletions(-) diff --git a/Userland/Utilities/CMakeLists.txt b/Userland/Utilities/CMakeLists.txt index 0818e2d37b..c28308ee3e 100644 --- a/Userland/Utilities/CMakeLists.txt +++ b/Userland/Utilities/CMakeLists.txt @@ -86,6 +86,7 @@ target_link_libraries(passwd LibCrypt) target_link_libraries(paste LibGUI) target_link_libraries(pgrep LibRegex) target_link_libraries(pls LibCrypt) +target_link_libraries(pmap LibMain) target_link_libraries(pro LibProtocol) target_link_libraries(run-tests LibRegex) target_link_libraries(shot LibGUI) diff --git a/Userland/Utilities/pmap.cpp b/Userland/Utilities/pmap.cpp index b37fdc7184..a558a9ab52 100644 --- a/Userland/Utilities/pmap.cpp +++ b/Userland/Utilities/pmap.cpp @@ -4,28 +4,19 @@ * SPDX-License-Identifier: BSD-2-Clause */ -#include #include #include #include #include #include -#include -#include +#include +#include -int main(int argc, char** argv) +ErrorOr serenity_main(Main::Arguments arguments) { - if (pledge("stdio rpath", nullptr) < 0) { - perror("pledge"); - return 1; - } - - if (unveil("/proc", "r") < 0) { - perror("unveil"); - return 1; - } - - unveil(nullptr, nullptr); + TRY(Core::System::pledge("stdio rpath", nullptr)); + TRY(Core::System::unveil("/proc", "r")); + TRY(Core::System::unveil(nullptr, nullptr)); const char* pid; static bool extended = false; @@ -33,13 +24,9 @@ int main(int argc, char** argv) Core::ArgsParser args_parser; args_parser.add_option(extended, "Extended output", nullptr, 'x'); args_parser.add_positional_argument(pid, "PID", "PID", Core::ArgsParser::Required::Yes); - args_parser.parse(argc, argv); + args_parser.parse(arguments); - auto file = Core::File::construct(String::formatted("/proc/{}/vm", pid)); - if (!file->open(Core::OpenMode::ReadOnly)) { - warnln("Failed to open {}: {}", file->name(), file->error_string()); - return 1; - } + auto file = TRY(Core::File::open(String::formatted("/proc/{}/vm", pid), Core::OpenMode::ReadOnly)); outln("{}:", pid); @@ -56,7 +43,7 @@ int main(int argc, char** argv) } auto file_contents = file->read_all(); - auto json = JsonValue::from_string(file_contents).release_value_but_fixme_should_propagate_errors(); + auto json = TRY(JsonValue::from_string(file_contents)); Vector sorted_regions = json.as_array().values(); quick_sort(sorted_regions, [](auto& a, auto& b) {