mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 09:24:57 +00: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
1 changed files with 6 additions and 0 deletions
|
@ -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…
Add table
Add a link
Reference in a new issue