From 7933741802a924fc2f0e39c8d58817aa4396146e Mon Sep 17 00:00:00 2001 From: Brent Cook Date: Sun, 15 Mar 2015 21:22:30 -0500 Subject: [PATCH] work around quirky behavior of Solaris adjtime I could not find a lot of precedence for this, because most time daemons do not actually look at the value of olddelta. Account for olddelta getting stuck at 1ms, and for a NULL value of delta being treated as an error condition. --- include/sys/time.h | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/include/sys/time.h b/include/sys/time.h index fe5b305..f40c5a7 100644 --- a/include/sys/time.h +++ b/include/sys/time.h @@ -3,8 +3,41 @@ * sys/time.h compatibility shim */ +#ifndef LIBCOMPAT_SYS_TIME_H +#define LIBCOMPAT_SYS_TIME_H + #include_next #include int adjfreq(const int64_t *freq, int64_t *oldfreq); + +#ifdef __sun +static inline int sun_adjtime(struct timeval *delta, struct timeval *olddelta) +{ + struct timeval zero = {0}; + int rc; + + /* + * adjtime on Solaris appears to handle a NULL delta differently than + * other OSes. Fill in a dummy value as necessary. + */ + if (delta) + rc = adjtime(delta, olddelta); + else + rc = adjtime(&zero, olddelta); + + /* + * Old delta on Solaris frequently gets stuck with 1 ms left. + * Round down to 0 in this case so we do not get flapping clock sync. + */ + if (rc == 0 && olddelta && + olddelta->tv_sec == 0 && olddelta->tv_usec == 1) + olddelta->tv_usec = 0; + + return rc; +} +#define adjtime(d, o) sun_adjtime(d, o) +#endif + +#endif