From a51e233f88593dde755a19afab6d9722c07c50d5 Mon Sep 17 00:00:00 2001 From: David Woodhouse Date: Thu, 19 Apr 2012 23:10:21 +0100 Subject: [PATCH] Work around time() brokenness on Solaris. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On Solaris and OpenIndiana, time() goes backwards. It and gettimeofday() occasionally jump back to 1970 and return zero seconds — although the tv_usec field is still sane, bizarrely. CR7121035 in Solaris, https://www.illumos.org/issues/1871 in OpenIndiana. It seems that gethrtime() doesn't suffer the same problem, so let's use that instead of time() for now. Signed-off-by: David Woodhouse --- Makefile.am | 2 +- compat.c | 39 +++++++++++++++++++++++++++++++++++++++ openconnect-internal.h | 4 ++++ 3 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 compat.c diff --git a/Makefile.am b/Makefile.am index 8abc0afe..876523f8 100644 --- a/Makefile.am +++ b/Makefile.am @@ -17,7 +17,7 @@ openconnect_SOURCES = xml.c main.c dtls.c cstp.c mainloop.c tun.c openconnect_CFLAGS = $(OPENSSL_CFLAGS) $(LIBXML2_CFLAGS) $(LIBPROXY_CFLAGS) $(ZLIB_CFLAGS) openconnect_LDADD = libopenconnect.la $(OPENSSL_LIBS) $(LIBXML2_LIBS) $(LIBPROXY_LIBS) $(ZLIB_LIBS) $(LIBINTL) -library_srcs = ssl.c http.c auth.c library.c +library_srcs = ssl.c http.c auth.c library.c compat.c libopenconnect_la_SOURCES = version.c $(library_srcs) libopenconnect_la_CFLAGS = $(OPENSSL_CFLAGS) $(LIBXML2_CFLAGS) $(LIBPROXY_CFLAGS) libopenconnect_la_LIBADD = $(OPENSSL_LIBS) $(LIBXML2_LIBS) $(LIBPROXY_LIBS) $(LIBINTL) diff --git a/compat.c b/compat.c new file mode 100644 index 00000000..d0fb4919 --- /dev/null +++ b/compat.c @@ -0,0 +1,39 @@ +/* + * OpenConnect (SSL + DTLS) VPN client + * + * Copyright © 2008-2012 Intel Corporation. + * + * Authors: David Woodhouse + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * version 2.1, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to: + * + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA + */ + +#include "openconnect-internal.h" + +#ifdef __sun__ +#include + +time_t openconnect__time(time_t *t) +{ + time_t s = gethrtime() / 1000000000LL; + if (t) + *t = s; + + return s; +} +#endif + diff --git a/openconnect-internal.h b/openconnect-internal.h index 51bbabce..e9d2ce7c 100644 --- a/openconnect-internal.h +++ b/openconnect-internal.h @@ -240,6 +240,10 @@ struct openconnect_info { /****************************************************************************/ /* Oh Solaris how we hate thee! */ +#ifdef __sun__ +#define time(x) openconnect__time(x) +time_t openconnect__time(time_t *t); +#endif #ifndef HAVE_ASPRINTF #define asprintf openconnect__asprintf int openconnect__asprintf(char **strp, const char *fmt, ...);