On Tue, Apr 30 2019, Jeremie Courreges-Anglas <j...@wxcvbn.org> wrote: > libevent contains a fallback path in case clock_gettime(CLOCK_MONOTONIC) > fails. The fallback path tries to cope with time going backwards and > reaches into the timeheap internals, as noticed by Tobias in > > https://marc.info/?l=openbsd-tech&m=155595247719664&w=2 > > I doubt that we care about this kind of seldom-tested compat code, which > was probably useful to get portable libevent to run on various > (ancient?) systems. > > Our clock_gettime can only fail for two reasons: > - invalid clock id. Lots of our userland uses CLOCK_MONOTONIC now, > I think it can be considered a requirement. > - invalid timespec pointer. Here, since we pass the address of > a timespec structure on the stack something must be really wrong if we > get EFAULT. > > So the diff below removes the fallback path and all associated code and > variables.
> I have left out some minor cleanups for now to ease reviews. Here's a diff that amends the signature of gettime() and makes use of TIMESPEC_TO_TIMEVAL(). Index: event.c =================================================================== --- event.c.orig +++ event.c @@ -77,23 +77,20 @@ static void event_process_active(struct static int timeout_next(struct event_base *, struct timeval **); static void timeout_process(struct event_base *); -static int +static void gettime(struct event_base *base, struct timeval *tp) { struct timespec ts; if (base->tv_cache.tv_sec) { *tp = base->tv_cache; - return (0); + return; } if (clock_gettime(CLOCK_MONOTONIC, &ts) == -1) event_err(1, "libevent: clock_gettime failed"); - tp->tv_sec = ts.tv_sec; - tp->tv_usec = ts.tv_nsec / 1000; - - return (0); + TIMESPEC_TO_TIMEVAL(tp, &ts); } struct event_base * @@ -803,8 +800,7 @@ timeout_next(struct event_base *base, st return (0); } - if (gettime(base, &now) == -1) - return (-1); + gettime(base, &now); if (timercmp(&ev->ev_timeout, &now, <=)) { timerclear(tv); -- jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF DDCC 0DFA 74AE 1524 E7EE