mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 08:54:58 +00:00
sleep: Port to LibMain
This commit is contained in:
parent
55496ab7fb
commit
a79e730839
2 changed files with 9 additions and 8 deletions
|
@ -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);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue