mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 12:07:45 +00:00
pmap: Port to LibMain :^)
This commit is contained in:
parent
d8482134b6
commit
8b5c0e8e71
2 changed files with 10 additions and 22 deletions
|
@ -86,6 +86,7 @@ target_link_libraries(passwd LibCrypt)
|
||||||
target_link_libraries(paste LibGUI)
|
target_link_libraries(paste LibGUI)
|
||||||
target_link_libraries(pgrep LibRegex)
|
target_link_libraries(pgrep LibRegex)
|
||||||
target_link_libraries(pls LibCrypt)
|
target_link_libraries(pls LibCrypt)
|
||||||
|
target_link_libraries(pmap LibMain)
|
||||||
target_link_libraries(pro LibProtocol)
|
target_link_libraries(pro LibProtocol)
|
||||||
target_link_libraries(run-tests LibRegex)
|
target_link_libraries(run-tests LibRegex)
|
||||||
target_link_libraries(shot LibGUI)
|
target_link_libraries(shot LibGUI)
|
||||||
|
|
|
@ -4,28 +4,19 @@
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <AK/Assertions.h>
|
|
||||||
#include <AK/JsonObject.h>
|
#include <AK/JsonObject.h>
|
||||||
#include <AK/QuickSort.h>
|
#include <AK/QuickSort.h>
|
||||||
#include <AK/String.h>
|
#include <AK/String.h>
|
||||||
#include <LibCore/ArgsParser.h>
|
#include <LibCore/ArgsParser.h>
|
||||||
#include <LibCore/File.h>
|
#include <LibCore/File.h>
|
||||||
#include <stdio.h>
|
#include <LibCore/System.h>
|
||||||
#include <unistd.h>
|
#include <LibMain/Main.h>
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
{
|
{
|
||||||
if (pledge("stdio rpath", nullptr) < 0) {
|
TRY(Core::System::pledge("stdio rpath", nullptr));
|
||||||
perror("pledge");
|
TRY(Core::System::unveil("/proc", "r"));
|
||||||
return 1;
|
TRY(Core::System::unveil(nullptr, nullptr));
|
||||||
}
|
|
||||||
|
|
||||||
if (unveil("/proc", "r") < 0) {
|
|
||||||
perror("unveil");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
unveil(nullptr, nullptr);
|
|
||||||
|
|
||||||
const char* pid;
|
const char* pid;
|
||||||
static bool extended = false;
|
static bool extended = false;
|
||||||
|
@ -33,13 +24,9 @@ int main(int argc, char** argv)
|
||||||
Core::ArgsParser args_parser;
|
Core::ArgsParser args_parser;
|
||||||
args_parser.add_option(extended, "Extended output", nullptr, 'x');
|
args_parser.add_option(extended, "Extended output", nullptr, 'x');
|
||||||
args_parser.add_positional_argument(pid, "PID", "PID", Core::ArgsParser::Required::Yes);
|
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));
|
auto file = TRY(Core::File::open(String::formatted("/proc/{}/vm", pid), Core::OpenMode::ReadOnly));
|
||||||
if (!file->open(Core::OpenMode::ReadOnly)) {
|
|
||||||
warnln("Failed to open {}: {}", file->name(), file->error_string());
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
outln("{}:", pid);
|
outln("{}:", pid);
|
||||||
|
|
||||||
|
@ -56,7 +43,7 @@ int main(int argc, char** argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
auto file_contents = file->read_all();
|
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<JsonValue> sorted_regions = json.as_array().values();
|
Vector<JsonValue> sorted_regions = json.as_array().values();
|
||||||
quick_sort(sorted_regions, [](auto& a, auto& b) {
|
quick_sort(sorted_regions, [](auto& a, auto& b) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue