diff options
author | Stef Walter <stefw@gnome.org> | 2014-09-09 15:06:10 +0200 |
---|---|---|
committer | Stef Walter <stefw@gnome.org> | 2014-09-09 15:06:10 +0200 |
commit | fa25db485279f5bc99a202db2ebeff00819a097f (patch) | |
tree | d1b8cf20195969d964b983aabb0018af5628f4ef /egg | |
parent | 2440aac3bc29890e07ce9a4260b0c6ad8d7bc037 (diff) | |
download | gnome-keyring-fa25db485279f5bc99a202db2ebeff00819a097f.tar.gz |
egg: Accomodate thread-safe libgcrypt 1.6+
libcrypt no longer supports setting our own threading callbacks,
and is thread-safe if we call gcry_check_version() before creating
threads.
Unfortunately we can't guarantee that we call gcry_check_version()
early enough, we try our best. Most of the callers of Gcr either
don't use libgcrypt, or also initialize it appropriately themselves.
Bump libgcrypt dependency to 1.4.5+, and have earlier versions use
the native pthread implementation of locking.
Diffstat (limited to 'egg')
-rw-r--r-- | egg/egg-libgcrypt.c | 45 |
1 files changed, 8 insertions, 37 deletions
diff --git a/egg/egg-libgcrypt.c b/egg/egg-libgcrypt.c index a7f3de66..ec991bcc 100644 --- a/egg/egg-libgcrypt.c +++ b/egg/egg-libgcrypt.c @@ -27,6 +27,8 @@ #include <gcrypt.h> +#include <errno.h> + EGG_SECURE_DECLARE (libgcrypt); static void @@ -52,42 +54,9 @@ fatal_handler (gpointer unused, int unknown, const gchar *msg) g_log ("gcrypt", G_LOG_LEVEL_ERROR, "%s", msg); } -static int -glib_thread_mutex_init (void **lock) -{ - *lock = g_new0 (GMutex, 1); - g_mutex_init (*lock); - return 0; -} - -static int -glib_thread_mutex_destroy (void **lock) -{ - g_mutex_clear (*lock); - g_free (*lock); - return 0; -} - -static int -glib_thread_mutex_lock (void **lock) -{ - g_mutex_lock (*lock); - return 0; -} - -static int -glib_thread_mutex_unlock (void **lock) -{ - g_mutex_unlock (*lock); - return 0; -} - -static struct gcry_thread_cbs glib_thread_cbs = { - GCRY_THREAD_OPTION_USER, NULL, - glib_thread_mutex_init, glib_thread_mutex_destroy, - glib_thread_mutex_lock, glib_thread_mutex_unlock, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL -}; +#if GCRYPT_VERSION_NUMBER < 0x010600 +GCRY_THREAD_OPTION_PTHREAD_IMPL; +#endif void egg_libgcrypt_initialize (void) @@ -99,7 +68,9 @@ egg_libgcrypt_initialize (void) /* Only initialize libgcrypt if it hasn't already been initialized */ if (!gcry_control (GCRYCTL_INITIALIZATION_FINISHED_P)) { - gcry_control (GCRYCTL_SET_THREAD_CBS, &glib_thread_cbs); +#if GCRYPT_VERSION_NUMBER < 0x010600 + gcry_control (GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread); +#endif gcry_check_version (LIBGCRYPT_VERSION); gcry_set_log_handler (log_handler, NULL); gcry_set_outofcore_handler (no_mem_handler, NULL); |