mirror of
https://gitlab.gnome.org/GNOME/libsecret.git
synced 2024-12-22 04:38:55 +00:00
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 libsecret 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.
This commit is contained in:
parent
c91de25db1
commit
5e2fe4afaa
@ -30,6 +30,8 @@
|
|||||||
|
|
||||||
#include <gcrypt.h>
|
#include <gcrypt.h>
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
EGG_SECURE_DECLARE (libgcrypt);
|
EGG_SECURE_DECLARE (libgcrypt);
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -55,42 +57,9 @@ fatal_handler (gpointer unused, int unknown, const gchar *msg)
|
|||||||
g_log ("gcrypt", G_LOG_LEVEL_ERROR, "%s", msg);
|
g_log ("gcrypt", G_LOG_LEVEL_ERROR, "%s", msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
#if GCRYPT_VERSION_NUMBER < 0x010600
|
||||||
glib_thread_mutex_init (void **lock)
|
GCRY_THREAD_OPTION_PTHREAD_IMPL;
|
||||||
{
|
#endif
|
||||||
*lock = g_slice_new (GMutex);
|
|
||||||
g_mutex_init (*lock);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
|
||||||
glib_thread_mutex_destroy (void **lock)
|
|
||||||
{
|
|
||||||
g_mutex_clear (*lock);
|
|
||||||
g_slice_free (GMutex, *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
|
|
||||||
};
|
|
||||||
|
|
||||||
void
|
void
|
||||||
egg_libgcrypt_initialize (void)
|
egg_libgcrypt_initialize (void)
|
||||||
@ -102,7 +71,9 @@ egg_libgcrypt_initialize (void)
|
|||||||
|
|
||||||
/* Only initialize libgcrypt if it hasn't already been initialized */
|
/* Only initialize libgcrypt if it hasn't already been initialized */
|
||||||
if (!gcry_control (GCRYCTL_INITIALIZATION_FINISHED_P)) {
|
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_check_version (LIBGCRYPT_VERSION);
|
||||||
gcry_set_log_handler (log_handler, NULL);
|
gcry_set_log_handler (log_handler, NULL);
|
||||||
gcry_set_outofcore_handler (no_mem_handler, NULL);
|
gcry_set_outofcore_handler (no_mem_handler, NULL);
|
||||||
|
Loading…
Reference in New Issue
Block a user