libc: consistency of tv_sec when tv_nsec wraps

The libc's internal calculation of the tv_sec and tv_nsec fields must be
based on the same ms value. Otherwise, tv_sec is not always immediately
incremented whenever tv_nsec wraps. For applications, this inconsistency
can result in observed jumps in time.

Fixes #5098
This commit is contained in:
Norman Feske 2024-01-24 13:51:15 +01:00 committed by Christian Helmuth
parent 684de7a57b
commit de6048f517

View File

@ -116,7 +116,7 @@ struct Libc::Rtc : Vfs::Watch_response_handler
msecs_since_rtc_update.value / 1000;
result.tv_sec = _rtc_value + seconds_since_rtc_update;
result.tv_nsec = (current_msecs.value % 1000) * (1000*1000);
result.tv_nsec = (msecs_since_rtc_update.value % 1000) * (1000*1000);
return result;
}