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:
AnotherTest 2021-03-30 02:29:07 +04:30 committed by Andreas Kling
parent 5d19509616
commit e8cfa43717
Notes: sideshowbarker 2024-07-18 20:55:56 +09:00

View File

@ -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);
}