From 3d63e688f7c486cd209d40687aaad18750e2729a Mon Sep 17 00:00:00 2001 From: Junior Rantila Date: Wed, 24 Nov 2021 16:36:07 +0100 Subject: [PATCH] watch: Port to LibMain --- Userland/Utilities/CMakeLists.txt | 1 + Userland/Utilities/watch.cpp | 22 +++++++++------------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/Userland/Utilities/CMakeLists.txt b/Userland/Utilities/CMakeLists.txt index c0762475f8..b02bfbbacf 100644 --- a/Userland/Utilities/CMakeLists.txt +++ b/Userland/Utilities/CMakeLists.txt @@ -149,4 +149,5 @@ target_link_libraries(cpp-preprocessor LibCpp LibGUI) target_link_libraries(w LibMain) target_link_libraries(wasm LibWasm LibLine) target_link_libraries(whoami LibMain) +target_link_libraries(watch LibMain) target_link_libraries(wsctl LibGUI) diff --git a/Userland/Utilities/watch.cpp b/Userland/Utilities/watch.cpp index 558d8c9b4e..7c3788a192 100644 --- a/Userland/Utilities/watch.cpp +++ b/Userland/Utilities/watch.cpp @@ -12,6 +12,8 @@ #include #include #include +#include +#include #include #include #include @@ -105,13 +107,10 @@ static int run_command(Vector const& command) } } -int main(int argc, char** argv) +ErrorOr serenity_main(Main::Arguments arguments) { - signal(SIGINT, handle_signal); - if (pledge("stdio proc exec rpath", nullptr) < 0) { - perror("pledge"); - return 1; - } + TRY(Core::System::signal(SIGINT, handle_signal)); + TRY(Core::System::pledge("stdio proc exec rpath", nullptr)); Vector files_to_watch; Vector command; @@ -134,7 +133,7 @@ int main(int argc, char** argv) }; args_parser.add_option(move(file_arg)); args_parser.add_positional_argument(command, "Command to run", "command"); - args_parser.parse(argc, argv); + args_parser.parse(arguments); command.append(nullptr); @@ -169,8 +168,8 @@ int main(int argc, char** argv) return 1; } if (!file_watcher.is_watching(file)) { - auto success_or_error = file_watcher.add_watch(file, Core::FileWatcherEvent::Type::MetadataModified); - if (success_or_error.is_error() && !success_or_error.value()) { + auto could_add_to_watch = TRY(file_watcher.add_watch(file, Core::FileWatcherEvent::Type::MetadataModified)); + if (!could_add_to_watch) { warnln("Could not add '{}' to watch list.", file); return 1; } @@ -185,10 +184,7 @@ int main(int argc, char** argv) } } } else { - if (pledge("stdio proc exec", nullptr) < 0) { - perror("pledge"); - return 1; - } + TRY(Core::System::pledge("stdio proc exec", nullptr)); struct timeval interval; if (opt_interval <= 0) {