summaryrefslogtreecommitdiff
path: root/Userland/Utilities
diff options
context:
space:
mode:
authorRiccardo Arena <riccardo@puntoquindici.it>2022-02-08 23:22:52 +0100
committerLinus Groh <mail@linusgroh.de>2022-02-10 14:10:58 +0000
commita9b387a1bff0a21438ba7e0c5ecefa4eae15d192 (patch)
tree59e00ed16d75bce9312509cb8578c55f7361e8dd /Userland/Utilities
parent5c63537ae93eee7da80c6135ab1119f5a8de8623 (diff)
downloadserenity-a9b387a1bff0a21438ba7e0c5ecefa4eae15d192.zip
pgrep: Port to LibMain
Use unveil to allow access only to required paths. Switch to new pledge format.
Diffstat (limited to 'Userland/Utilities')
-rw-r--r--Userland/Utilities/CMakeLists.txt2
-rw-r--r--Userland/Utilities/pgrep.cpp14
2 files changed, 9 insertions, 7 deletions
diff --git a/Userland/Utilities/CMakeLists.txt b/Userland/Utilities/CMakeLists.txt
index 8b7442fbb8..459e993511 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 419bbb3c39..a35e278424 100644
--- a/Userland/Utilities/pgrep.cpp
+++ b/Userland/Utilities/pgrep.cpp
@@ -8,14 +8,16 @@
#include <AK/Vector.h>
#include <LibCore/ArgsParser.h>
#include <LibCore/ProcessStatisticsReader.h>
+#include <LibCore/System.h>
+#include <LibMain/Main.h>
#include <LibRegex/Regex.h>
-int main(int argc, char** argv)
+ErrorOr<int> 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)