diff options
author | 2018-03-07 17:17:47 +0000 | |
---|---|---|
committer | 2018-03-07 17:17:47 +0000 | |
commit | 62f07b25bdd968b3fd75b30b4d3f23fe17e878b2 (patch) | |
tree | c7db06d6d7ec271a87f5e2a8cefb36793ce6304b /lib/libtls/tls.c | |
parent | add "int stall" argument required by filesystem stall code; from Tomohiro Kusumi (diff) | |
download | wireguard-openbsd-62f07b25bdd968b3fd75b30b4d3f23fe17e878b2.tar.xz wireguard-openbsd-62f07b25bdd968b3fd75b30b4d3f23fe17e878b2.zip |
Make tls_init() concurrently callable using pthread_once().
ok jsing@
This brings pthread_once usage into libressl, which will
need to get dealt with correctly in portable.
This sets us up to autoinit libtls, and we will also be
using pthread_once to deal with autoinit stuff in libssl
and libcrypto
Diffstat (limited to 'lib/libtls/tls.c')
-rw-r--r-- | lib/libtls/tls.c | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/lib/libtls/tls.c b/lib/libtls/tls.c index 8f2c7dde057..4a9db289bd6 100644 --- a/lib/libtls/tls.c +++ b/lib/libtls/tls.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tls.c,v 1.75 2018/02/10 04:57:35 jsing Exp $ */ +/* $OpenBSD: tls.c,v 1.76 2018/03/07 17:17:47 beck Exp $ */ /* * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> * @@ -19,6 +19,7 @@ #include <errno.h> #include <limits.h> +#include <pthread.h> #include <stdlib.h> #include <unistd.h> @@ -35,28 +36,35 @@ static struct tls_config *tls_config_default; -int -tls_init(void) -{ - static int tls_initialised = 0; - - if (tls_initialised) - return (0); +static int tls_init_rv = -1; +static void +tls_do_init(void) +{ SSL_load_error_strings(); SSL_library_init(); if (BIO_sock_init() != 1) - return (-1); + return; if ((tls_config_default = tls_config_new()) == NULL) - return (-1); + return; tls_config_default->refcount++; - tls_initialised = 1; + tls_init_rv = 0; + return; +} - return (0); +int +tls_init(void) +{ + static pthread_once_t once = PTHREAD_ONCE_INIT; + + if (pthread_once(&once, tls_do_init) != 0) + return -1; + + return tls_init_rv; } const char * |