From a9b387a1bff0a21438ba7e0c5ecefa4eae15d192 Mon Sep 17 00:00:00 2001 From: Riccardo Arena Date: Tue, 8 Feb 2022 23:22:52 +0100 Subject: [PATCH] pgrep: Port to LibMain Use unveil to allow access only to required paths. Switch to new pledge format. --- Userland/Utilities/CMakeLists.txt | 2 +- Userland/Utilities/pgrep.cpp | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Userland/Utilities/CMakeLists.txt b/Userland/Utilities/CMakeLists.txt index 8b7442fbb8c..459e993511f 100644 --- a/Userland/Utilities/CMakeLists.txt +++ b/Userland/Utilities/CMakeLists.txt @@ -146,7 +146,7 @@ target_link_libraries(open LibDesktop LibMain) target_link_libraries(pape LibGUI LibMain) target_link_libraries(passwd LibCrypt LibMain) target_link_libraries(paste LibGUI) -target_link_libraries(pgrep LibRegex) +target_link_libraries(pgrep LibRegex LibMain) target_link_libraries(pidof LibMain) target_link_libraries(ping LibMain) target_link_libraries(pls LibCrypt LibMain) diff --git a/Userland/Utilities/pgrep.cpp b/Userland/Utilities/pgrep.cpp index 419bbb3c39f..a35e2784242 100644 --- a/Userland/Utilities/pgrep.cpp +++ b/Userland/Utilities/pgrep.cpp @@ -8,14 +8,16 @@ #include #include #include +#include +#include #include -int main(int argc, char** argv) +ErrorOr serenity_main(Main::Arguments args) { - if (pledge("stdio rpath", nullptr) < 0) { - perror("pledge"); - return 1; - } + TRY(Core::System::pledge("stdio rpath")); + TRY(Core::System::unveil("/proc/all", "r")); + TRY(Core::System::unveil("/etc/passwd", "r")); + TRY(Core::System::unveil(nullptr, nullptr)); bool case_insensitive = false; bool invert_match = false; @@ -25,7 +27,7 @@ int main(int argc, char** argv) args_parser.add_option(case_insensitive, "Make matches case-insensitive", nullptr, 'i'); args_parser.add_option(invert_match, "Select non-matching lines", "invert-match", 'v'); args_parser.add_positional_argument(pattern, "Process name to search for", "process-name"); - args_parser.parse(argc, argv); + args_parser.parse(args); PosixOptions options {}; if (case_insensitive)