[gnome-keyring] egg: Accomodate thread-safe libgcrypt 1.6+



commit fa25db485279f5bc99a202db2ebeff00819a097f
Author: Stef Walter <stefw gnome org>
Date:   Tue Sep 9 15:06:10 2014 +0200

    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.

 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 a7f3de6..ec991bc 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);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]