Closed aloisklink closed 1 year ago
Great find. Can you provide a fix as a PR?
Great find. Can you provide a fix as a PR?
:+1: I'll stick it on my todo-list, but since this is a bit of a high/medium-priority issue, it might take a while to get to it!
It looks like standard ISO C has clock()
that we can use for this, but there's a bunch of warnings about non-conforming implementations, so it might be better to use the clock_gettime()
with CLOCK_MONOTONIC
from POSIX C.
Describe the bug
The current implementation of
os_get_reltime
returns the actual time, instead of the relative time.To Reproduce
os_get_reltime()
.os_get_reltime()
may go backwards.Expected behavior
Every call to
os_get_reltime()
shows the actual relative time compared to when the program started running.Additionally, the result of
os_get_reltime()
should never be lower than previous calls.Additional context
It's one of the falsehoods programmers believe about time :laughing:
man gettimeofday(2)
also recommends usingclock_gettime()
.hostapd also has a better implementation that we can use, (see https://w1.fi/cgit/hostap/commit/?id=594516b4c28a94ca686b17f1e463dfd6712b75a7) but it might be Linux specific and not work on FreeBSD/CheriBSD.