diff options
author | alexmajor <5017286+alexmajor@users.noreply.github.com> | 2022-01-24 20:27:22 -0500 |
---|---|---|
committer | Brian Gianforcaro <b.gianfo@gmail.com> | 2022-02-01 04:58:24 +0000 |
commit | a79e730839cf5ea0c4790d5ed613775bb448129e (patch) | |
tree | d3173d0c2a23fed12b5dc0c948e198590f93fed1 /Userland | |
parent | 55496ab7fbf1e35c76e9fc9b4d591d24c0468a9a (diff) | |
download | serenity-a79e730839cf5ea0c4790d5ed613775bb448129e.zip |
sleep: Port to LibMain
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Utilities/CMakeLists.txt | 3 | ||||
-rw-r--r-- | Userland/Utilities/sleep.cpp | 14 |
2 files changed, 9 insertions, 8 deletions
diff --git a/Userland/Utilities/CMakeLists.txt b/Userland/Utilities/CMakeLists.txt index f04cf50568..fb73425f0c 100644 --- a/Userland/Utilities/CMakeLists.txt +++ b/Userland/Utilities/CMakeLists.txt @@ -161,8 +161,9 @@ target_link_libraries(run-tests LibRegex LibCoredump) target_link_libraries(shot LibGUI LibMain) target_link_libraries(shuf LibMain) target_link_libraries(shutdown LibMain) -target_link_libraries(sql LibLine LibMain LibSQL LibIPC) +target_link_libraries(sleep LibMain) target_link_libraries(sort LibMain) +target_link_libraries(sql LibLine LibMain LibSQL LibIPC) target_link_libraries(stat LibMain) target_link_libraries(strace LibMain) target_link_libraries(stty LibMain) diff --git a/Userland/Utilities/sleep.cpp b/Userland/Utilities/sleep.cpp index 50d3b3031a..16c6c11001 100644 --- a/Userland/Utilities/sleep.cpp +++ b/Userland/Utilities/sleep.cpp @@ -1,10 +1,13 @@ /* * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> + * Copyright (c) 2022, Alex Major * * SPDX-License-Identifier: BSD-2-Clause */ #include <LibCore/ArgsParser.h> +#include <LibCore/System.h> +#include <LibMain/Main.h> #include <errno.h> #include <signal.h> #include <stdio.h> @@ -18,23 +21,20 @@ static void handle_sigint(int) g_interrupted = true; } -int main(int argc, char** argv) +ErrorOr<int> serenity_main(Main::Arguments arguments) { double secs; Core::ArgsParser args_parser; args_parser.add_positional_argument(secs, "Number of seconds to sleep for", "num-seconds"); - args_parser.parse(argc, argv); + args_parser.parse(arguments); struct sigaction sa; memset(&sa, 0, sizeof(struct sigaction)); sa.sa_handler = handle_sigint; sigaction(SIGINT, &sa, nullptr); - if (pledge("stdio sigaction", nullptr) < 0) { - perror("pledge"); - return 1; - } + TRY(Core::System::pledge("stdio sigaction", nullptr)); double whole_seconds = static_cast<time_t>(secs); double fraction = secs - whole_seconds; @@ -63,7 +63,7 @@ sleep_again: outln("Sleep interrupted with {}.{} seconds remaining.", remaining_sleep.tv_sec, remaining_sleep.tv_nsec); } - signal(SIGINT, SIG_DFL); + TRY(Core::System::signal(SIGINT, SIG_DFL)); if (g_interrupted) raise(SIGINT); |