From e8cfa437171c5f9f5e0b520499ece6d95ca9a925 Mon Sep 17 00:00:00 2001 From: AnotherTest Date: Tue, 30 Mar 2021 02:29:07 +0430 Subject: [PATCH] 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. --- Userland/Utilities/sleep.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Userland/Utilities/sleep.cpp b/Userland/Utilities/sleep.cpp index 4cd24d2f30..61584ce19e 100644 --- a/Userland/Utilities/sleep.cpp +++ b/Userland/Utilities/sleep.cpp @@ -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); }