Re: [exim] Exim clock offset and CLOCK_MONOTONIC timer

Top Pagina
Delete this message
Reply to this message
Auteur: Martin Preen
Datum:  
Aan: exim-users
Onderwerp: Re: [exim] Exim clock offset and CLOCK_MONOTONIC timer
On 26.08.21 15:08, Martin Preen via Exim-users wrote:
> Hi,
> I think there is a problem with the Solaris version of Exim.
>
> The symptoms I've seen are negative RT log entries and negative $message_age values.
> But there maybe more. With a SIGHUP the negative values disappear (temporarily).
>
> I've read the sources and manual pages and maybe this is the reason:
>
> Exim calculates an offset of the CLOCK_MONOTONIC timer once at the start of the program
> and this offset is used to calculate the real receive time of an incoming message.
>
> This is fine if CLOCK_REALTIME and CLOCK_MONOTONIC timers are both updated by adjtime
> or other calls (e.g. via ntpd/ntpdate). This is the case with Linux and AFAIK this also
> applies to CLOCK_BOOTTIME. On Solaris CLOCK_MONOTONIC isn't updated by clock drifts.
>
> Thus, depending on the clock drifts of a particuliar system,
> the offset may become wrong in a long running process.
>
> There seems to be no equivalent to the Linux variant of CLOCK_MONOTONIC on Solaris.
> Only for the opposite direction (see CLOCK_MONOTONIC_RAW on Linux).


Below is a small code change which may fix this. It just updates the offset regularly
(once per minute) to increase Exim clock accuracy. But I'm unsure if there are other
things to consider when dealing with clock issues. It would be great if some fix
will be included to Exim.

Regards,
Martin


file exim.c:

void
exim_gettime(struct timeval * tv)
{
#ifdef _POSIX_MONOTONIC_CLOCK
struct timespec now_ts;

+ static time_t ref_time=0;
+ time_t t;

+ t=time(NULL);
+ if ((ref_time!=0) && (t-ref_time>=60)) {exim_clock_init();}
+ ref_time=t;