Merge commit '7e934d3acc051b7ee3ef0d11571fd1225800a607'
[unleashed.git] / lib / libssl / ssl_init.c
blob0ef80956ed1729c76d8927360c5ab5e68cb6f601
1 /*
2 * Copyright (c) 2018 Bob Beck <beck@openbsd.org>
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 /* OpenSSL style init */
19 #include <pthread.h>
20 #include <stdio.h>
22 #include <openssl/objects.h>
24 #include "ssl_locl.h"
26 static pthread_t ssl_init_thread;
28 static void
29 OPENSSL_init_ssl_internal(void)
31 ssl_init_thread = pthread_self();
32 SSL_load_error_strings();
33 SSL_library_init();
36 int
37 OPENSSL_init_ssl(uint64_t opts, const void *settings)
39 static pthread_once_t once = PTHREAD_ONCE_INIT;
41 if (pthread_equal(pthread_self(), ssl_init_thread))
42 return 1; /* don't recurse */
44 OPENSSL_init_crypto(opts, settings);
46 if (pthread_once(&once, OPENSSL_init_ssl_internal) != 0)
47 return 0;
49 return 1;