Skip to content

Commit

Permalink
Fix sleep(0) resulting in infinite wait
Browse files Browse the repository at this point in the history
  • Loading branch information
Arshia001 committed Dec 20, 2024
1 parent d9e7fe2 commit c5fe4c6
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions libc-bottom-half/cloudlibc/src/libc/time/clock_nanosleep.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ int clock_nanosleep(clockid_t clock_id, int flags, const struct timespec *rqtp,
if (!timespec_to_timestamp_exact(rqtp, &sub.u.u.clock.timeout))
return EINVAL;

// a zero timeout is an infinite wait, while 1 is used to
// wait 0 seconds
if (sub.u.u.clock.timeout == 0)
sub.u.u.clock.timeout = 1;

// Block until polling event is triggered.
__wasi_size_t nevents;
__wasi_event_t ev;
Expand Down

0 comments on commit c5fe4c6

Please sign in to comment.