mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-06 02:55:49 +03:00
Utilities/sleep: Go back to sleep if not interrupted by SIGINT
This can happen if the process is stopped and continued at a later time.
This commit is contained in:
parent
5d19509616
commit
e8cfa43717
Notes:
sideshowbarker
2024-07-18 20:55:56 +09:00
Author: https://github.com/alimpfard Commit: https://github.com/SerenityOS/serenity/commit/e8cfa437171 Pull-request: https://github.com/SerenityOS/serenity/pull/6021
@ -65,6 +65,7 @@ int main(int argc, char** argv)
|
||||
|
||||
timespec remaining_sleep {};
|
||||
|
||||
sleep_again:
|
||||
if (clock_nanosleep(CLOCK_MONOTONIC, 0, &requested_sleep, &remaining_sleep) < 0) {
|
||||
if (errno != EINTR) {
|
||||
perror("clock_nanosleep");
|
||||
@ -73,6 +74,11 @@ int main(int argc, char** argv)
|
||||
}
|
||||
|
||||
if (remaining_sleep.tv_sec || remaining_sleep.tv_nsec) {
|
||||
if (!g_interrupted) {
|
||||
// If not interrupted with SIGINT, just go back to sleep.
|
||||
requested_sleep = remaining_sleep;
|
||||
goto sleep_again;
|
||||
}
|
||||
outln("Sleep interrupted with {}.{} seconds remaining.", remaining_sleep.tv_sec, remaining_sleep.tv_nsec);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user