summaryrefslogtreecommitdiff
path: root/src/global.c
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@dwim.me>2014-11-01 10:45:33 +0100
committerCarlos Martín Nieto <cmn@dwim.me>2014-11-01 10:58:55 +0100
commitfe6b51ae40313036436f81d4e87d232691cdacac (patch)
treeb6f18e6eff58f684da5b5e561574dba417bdb0ff /src/global.c
parente08365777199901d58e7cf4cc269ffabd07b2659 (diff)
downloadlibgit2-fe6b51ae40313036436f81d4e87d232691cdacac.tar.gz
ssl: separate locking init from general init
Extract the lock-setting functions into their own, as we cannot assume that it's ok for us to set this unconditionally.
Diffstat (limited to 'src/global.c')
-rw-r--r--src/global.c41
1 files changed, 23 insertions, 18 deletions
diff --git a/src/global.c b/src/global.c
index 2435b5673..3e721ee3a 100644
--- a/src/global.c
+++ b/src/global.c
@@ -64,7 +64,7 @@ void openssl_locking_function(int mode, int n, const char *file, int line)
}
}
-static void shutdown_ssl(void)
+static void shutdown_ssl_locking(void)
{
CRYPTO_set_locking_callback(NULL);
git__free(openssl_locks);
@@ -96,30 +96,35 @@ static void init_ssl(void)
SSL_CTX_free(git__ssl_ctx);
git__ssl_ctx = NULL;
}
+#endif
+}
+int git_openssl_set_locking(void)
+{
+#ifdef GIT_SSL
# ifdef GIT_THREADS
- {
- int num_locks, i;
-
- num_locks = CRYPTO_num_locks();
- openssl_locks = git__calloc(num_locks, sizeof(git_mutex));
- if (openssl_locks == NULL) {
- SSL_CTX_free(git__ssl_ctx);
- git__ssl_ctx = NULL;
- }
+ int num_locks, i;
- for (i = 0; i < num_locks; i++) {
- if (git_mutex_init(&openssl_locks[i]) != 0) {
- SSL_CTX_free(git__ssl_ctx);
- git__ssl_ctx = NULL;
- }
- }
+ num_locks = CRYPTO_num_locks();
+ openssl_locks = git__calloc(num_locks, sizeof(git_mutex));
+ GITERR_CHECK_ALLOC(openssl_locks);
- CRYPTO_set_locking_callback(openssl_locking_function);
+ for (i = 0; i < num_locks; i++) {
+ if (git_mutex_init(&openssl_locks[i]) != 0) {
+ giterr_set(GITERR_SSL, "failed to initialize openssl locks");
+ return -1;
+ }
}
- git__on_shutdown(shutdown_ssl);
+ CRYPTO_set_locking_callback(openssl_locking_function);
+ git__on_shutdown(shutdown_ssl_locking);
+ return 0;
+# else
+ giterr_set(GITERR_THREAD, "libgit2 as not built with threads");
+ return -1;
# endif
+ giterr_set(GITERR_SSL, "libgit2 was not built with OpenSSL support");
+ return -1;
#endif
}