summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--daemon/gkd-main.c1
-rw-r--r--daemon/gpg-agent/gkd-gpg-agent-standalone.c3
-rw-r--r--daemon/gpg-agent/gkd-gpg-agent.c18
-rw-r--r--daemon/ssh-agent/gkd-ssh-agent-standalone.c3
-rw-r--r--daemon/ssh-agent/gkd-ssh-agent.c18
-rw-r--r--egg/egg-libgcrypt.c10
-rw-r--r--egg/egg-testing.c90
-rw-r--r--pkcs11/gkm/gkm-timer.c45
-rw-r--r--pkcs11/gnome2-store/gkm-gnome2-standalone.c2
-rw-r--r--pkcs11/roots-store/gkm-roots-standalone.c3
-rw-r--r--pkcs11/rpc-layer/gkm-rpc-dispatch.c4
-rw-r--r--pkcs11/secret-store/gkm-secret-standalone.c3
-rw-r--r--pkcs11/ssh-store/gkm-ssh-standalone.c2
-rw-r--r--pkcs11/xdg-store/gkm-xdg-standalone.c2
-rw-r--r--tool/gkr-tool.c3
-rw-r--r--ui/gku-prompt.c14
16 files changed, 172 insertions, 49 deletions
diff --git a/daemon/gkd-main.c b/daemon/gkd-main.c
index 12d3de92..e9f43922 100644
--- a/daemon/gkd-main.c
+++ b/daemon/gkd-main.c
@@ -882,7 +882,6 @@ main (int argc, char *argv[])
#endif
g_type_init ();
- g_thread_init (NULL);
#ifdef HAVE_LOCALE_H
/* internationalisation */
diff --git a/daemon/gpg-agent/gkd-gpg-agent-standalone.c b/daemon/gpg-agent/gkd-gpg-agent-standalone.c
index c573e478..a9a1c997 100644
--- a/daemon/gpg-agent/gkd-gpg-agent-standalone.c
+++ b/daemon/gpg-agent/gkd-gpg-agent-standalone.c
@@ -79,9 +79,6 @@ main(int argc, char *argv[])
g_type_init ();
- if (!g_thread_supported ())
- g_thread_init (NULL);
-
if (argc <= 1) {
g_message ("specify pkcs11 module on the command line");
return 1;
diff --git a/daemon/gpg-agent/gkd-gpg-agent.c b/daemon/gpg-agent/gkd-gpg-agent.c
index 7e4aaf8f..0365c216 100644
--- a/daemon/gpg-agent/gkd-gpg-agent.c
+++ b/daemon/gpg-agent/gkd-gpg-agent.c
@@ -329,7 +329,11 @@ gkd_gpg_agent_accept (void)
client->sock = new_fd;
/* And create a new thread/process */
+#if GLIB_CHECK_VERSION(2,31,2)
+ client->thread = g_thread_new ("gpg-agent", run_client_thread, &client->sock);
+#else
client->thread = g_thread_create (run_client_thread, &client->sock, TRUE, &error);
+#endif
if (!client->thread) {
g_warning ("couldn't create thread GPG agent connection: %s",
error && error->message ? error->message : "");
@@ -385,8 +389,15 @@ gkd_gpg_agent_uninitialize (void)
pkcs11_main_session = NULL;
g_mutex_unlock (pkcs11_main_mutex);
+#if GLIB_CHECK_VERSION(2,31,2)
+ g_mutex_clear (pkcs11_main_mutex);
+ g_free (pkcs11_main_mutex);
+ g_cond_clear (pkcs11_main_cond);
+ g_free (pkcs11_main_cond);
+#else
g_mutex_free (pkcs11_main_mutex);
g_cond_free (pkcs11_main_cond);
+#endif
g_assert (pkcs11_module);
g_object_unref (pkcs11_module);
@@ -446,8 +457,15 @@ gkd_gpg_agent_initialize_with_module (GckModule *module)
pkcs11_module = g_object_ref (module);
+#if GLIB_CHECK_VERSION(2,31,2)
+ pkcs11_main_mutex = g_new0 (GMutex, 1);
+ g_mutex_init (pkcs11_main_mutex);
+ pkcs11_main_cond = g_new0 (GCond, 1);
+ g_cond_init (pkcs11_main_cond);
+#else
pkcs11_main_mutex = g_mutex_new ();
pkcs11_main_cond = g_cond_new ();
+#endif
pkcs11_main_checked = FALSE;
pkcs11_main_session = session;
diff --git a/daemon/ssh-agent/gkd-ssh-agent-standalone.c b/daemon/ssh-agent/gkd-ssh-agent-standalone.c
index 5879d178..a496a361 100644
--- a/daemon/ssh-agent/gkd-ssh-agent-standalone.c
+++ b/daemon/ssh-agent/gkd-ssh-agent-standalone.c
@@ -80,9 +80,6 @@ main(int argc, char *argv[])
g_type_init ();
- if (!g_thread_supported ())
- g_thread_init (NULL);
-
if (argc <= 1) {
g_message ("specify pkcs11 module on the command line");
return 1;
diff --git a/daemon/ssh-agent/gkd-ssh-agent.c b/daemon/ssh-agent/gkd-ssh-agent.c
index 2f836311..7ac1cc99 100644
--- a/daemon/ssh-agent/gkd-ssh-agent.c
+++ b/daemon/ssh-agent/gkd-ssh-agent.c
@@ -284,7 +284,11 @@ gkd_ssh_agent_accept (void)
client->sock = new_fd;
/* And create a new thread/process */
+#if GLIB_CHECK_VERSION(2,31,3)
+ client->thread = g_thread_new ("ssh-agent", run_client_thread, &client->sock);
+#else
client->thread = g_thread_create (run_client_thread, &client->sock, TRUE, &error);
+#endif
if (!client->thread) {
g_warning ("couldn't create thread SSH agent connection: %s",
egg_error_message (error));
@@ -340,8 +344,15 @@ gkd_ssh_agent_uninitialize (void)
pkcs11_main_session = NULL;
g_mutex_unlock (pkcs11_main_mutex);
+#if GLIB_CHECK_VERSION(2,31,3)
+ g_mutex_clear (pkcs11_main_mutex);
+ g_free (pkcs11_main_mutex);
+ g_cond_clear (pkcs11_main_cond);
+ g_free (pkcs11_main_cond);
+#else
g_mutex_free (pkcs11_main_mutex);
g_cond_free (pkcs11_main_cond);
+#endif
gck_list_unref_free (pkcs11_modules);
pkcs11_modules = NULL;
@@ -400,8 +411,15 @@ gkd_ssh_agent_initialize_with_module (GckModule *module)
g_assert (!pkcs11_modules);
pkcs11_modules = g_list_append (NULL, g_object_ref (module));
+#if GLIB_CHECK_VERSION(2,31,3)
+ pkcs11_main_mutex = g_new0 (GMutex, 1);
+ g_mutex_init (pkcs11_main_mutex);
+ pkcs11_main_cond = g_new0 (GCond, 1);
+ g_cond_init (pkcs11_main_cond);
+#else
pkcs11_main_mutex = g_mutex_new ();
pkcs11_main_cond = g_cond_new ();
+#endif
pkcs11_main_checked = FALSE;
pkcs11_main_session = session;
diff --git a/egg/egg-libgcrypt.c b/egg/egg-libgcrypt.c
index e5b3f558..63411639 100644
--- a/egg/egg-libgcrypt.c
+++ b/egg/egg-libgcrypt.c
@@ -56,14 +56,24 @@ fatal_handler (gpointer unused, int unknown, const gchar *msg)
static int
glib_thread_mutex_init (void **lock)
{
+#if GLIB_CHECK_VERSION(2,31,3)
+ *lock = g_new0 (GMutex, 1);
+ g_mutex_init (*lock);
+#else
*lock = g_mutex_new ();
+#endif
return 0;
}
static int
glib_thread_mutex_destroy (void **lock)
{
+#if GLIB_CHECK_VERSION(2,31,3)
+ g_mutex_clear (*lock);
+ g_free (*lock);
+#else
g_mutex_free (*lock);
+#endif
return 0;
}
diff --git a/egg/egg-testing.c b/egg/egg-testing.c
index 0235ac09..0269af6e 100644
--- a/egg/egg-testing.c
+++ b/egg/egg-testing.c
@@ -28,9 +28,16 @@
#include <errno.h>
#include <unistd.h>
+#if GLIB_CHECK_VERSION(2,31,3)
+static GCond wait_condition;
+static GCond wait_start;
+static GMutex wait_mutex;
+#else
static GCond *wait_condition = NULL;
static GCond *wait_start = NULL;
static GMutex *wait_mutex = NULL;
+#endif
+
static gboolean wait_waiting = FALSE;
static const char HEXC[] = "0123456789ABCDEF";
@@ -82,40 +89,73 @@ egg_assertion_message_cmpmem (const char *domain,
void
egg_test_wait_stop (void)
{
- GTimeVal tv;
-
- g_get_current_time (&tv);
- g_time_val_add (&tv, 1000);
-
+#if GLIB_CHECK_VERSION(2,31,3)
+ g_mutex_lock (&wait_mutex);
+#else
g_assert (wait_mutex);
g_assert (wait_condition);
g_mutex_lock (wait_mutex);
- if (!wait_waiting)
- g_cond_timed_wait (wait_start, wait_mutex, &tv);
- g_assert (wait_waiting);
- g_cond_broadcast (wait_condition);
+#endif
+
+ if (!wait_waiting) {
+#if GLIB_CHECK_VERSION(2,31,3)
+ gint64 time = g_get_monotonic_time () + 1 * G_TIME_SPAN_SECOND;
+ g_cond_wait_until (&wait_start, &wait_mutex, time);
+#else
+ GTimeVal tv;
+ g_get_current_time (&tv);
+ g_time_val_add (&tv, 1000);
+ g_cond_timed_wait (wait_start, wait_mutex, &tv);
+#endif
+ }
+ g_assert (wait_waiting);
+
+#if GLIB_CHECK_VERSION(2,31,3)
+ g_cond_broadcast (&wait_condition);
+ g_mutex_unlock (&wait_mutex);
+#else
+ g_cond_broadcast (wait_condition);
g_mutex_unlock (wait_mutex);
+#endif
}
gboolean
egg_test_wait_until (int timeout)
{
- GTimeVal tv;
gboolean ret;
- g_get_current_time (&tv);
- g_time_val_add (&tv, timeout * 1000);
-
+#if GLIB_CHECK_VERSION(2,31,3)
+ g_mutex_lock (&wait_mutex);
+#else
g_assert (wait_mutex);
g_assert (wait_condition);
g_mutex_lock (wait_mutex);
- g_assert (!wait_waiting);
- wait_waiting = TRUE;
+#endif
+
+ g_assert (!wait_waiting);
+ wait_waiting = TRUE;
+
+ {
+#if GLIB_CHECK_VERSION(2,31,3)
+ gint64 time = g_get_monotonic_time () + ((timeout + 1000) * G_TIME_SPAN_MILLISECOND);
+ g_cond_broadcast (&wait_start);
+ ret = g_cond_wait_until (&wait_start, &wait_mutex, time);
+#else
+ GTimeVal tv;
+ g_get_current_time (&tv);
+ g_time_val_add (&tv, timeout * 1000);
g_cond_broadcast (wait_start);
ret = g_cond_timed_wait (wait_condition, wait_mutex, &tv);
- g_assert (wait_waiting);
- wait_waiting = FALSE;
+#endif
+ }
+
+ g_assert (wait_waiting);
+ wait_waiting = FALSE;
+#if GLIB_CHECK_VERSION(2,31,3)
+ g_mutex_unlock (&wait_mutex);
+#else
g_mutex_unlock (wait_mutex);
+#endif
return ret;
}
@@ -136,22 +176,36 @@ egg_tests_run_in_thread_with_loop (void)
GMainLoop *loop;
gpointer ret;
+#if !GLIB_CHECK_VERSION(2,31,3)
g_thread_init (NULL);
+#endif
loop = g_main_loop_new (NULL, FALSE);
+#if GLIB_CHECK_VERSION(2,31,3)
+ g_cond_init (&wait_condition);
+ g_cond_init (&wait_start);
+ g_mutex_init (&wait_mutex);
+ thread = g_thread_new ("testing", testing_thread, loop);
+#else
wait_condition = g_cond_new ();
wait_start = g_cond_new ();
wait_mutex = g_mutex_new ();
-
thread = g_thread_create (testing_thread, loop, TRUE, NULL);
+#endif
+
g_assert (thread);
g_main_loop_run (loop);
ret = g_thread_join (thread);
g_main_loop_unref (loop);
+#if GLIB_CHECK_VERSION(2,31,2)
+ g_cond_clear (&wait_condition);
+ g_mutex_clear (&wait_mutex);
+#else
g_cond_free (wait_condition);
g_mutex_free (wait_mutex);
+#endif
return GPOINTER_TO_INT (ret);
}
diff --git a/pkcs11/gkm/gkm-timer.c b/pkcs11/gkm/gkm-timer.c
index bde8ce10..f747975f 100644
--- a/pkcs11/gkm/gkm-timer.c
+++ b/pkcs11/gkm/gkm-timer.c
@@ -38,6 +38,9 @@ struct _GkmTimer {
static GStaticMutex timer_mutex = G_STATIC_MUTEX_INIT;
static GQueue *timer_queue = NULL;
static GThread *timer_thread = NULL;
+#if GLIB_CHECK_VERSION(2,31,3)
+static GCond timer_condition;
+#endif
static GCond *timer_cond = NULL;
static gboolean timer_run = FALSE;
static gint timer_refs = 0;
@@ -57,7 +60,6 @@ timer_thread_func (gpointer unused)
{
GMutex *mutex = g_static_mutex_get_mutex (&timer_mutex);
GkmTimer *timer;
- GTimeVal tv;
g_mutex_lock (mutex);
@@ -70,14 +72,26 @@ timer_thread_func (gpointer unused)
continue;
}
- g_get_current_time (&tv);
-
- /* We have to wait until the next timer? */
- if (tv.tv_sec < timer->when) {
- tv.tv_sec = timer->when;
- tv.tv_usec = 0;
- g_cond_timed_wait (timer_cond, mutex, &tv);
- continue;
+ if (timer->when) {
+#if GLIB_CHECK_VERSION(2,31,3)
+ gint64 when = ((gint64)timer->when) * G_TIME_SPAN_SECOND;
+ gint64 offset = when - g_get_real_time ();
+ if (offset > 0) {
+ g_cond_wait_until (timer_cond, mutex, g_get_monotonic_time () + offset);
+ continue;
+ }
+#else
+ GTimeVal tv;
+ g_get_current_time (&tv);
+
+ /* We have to wait until the next timer? */
+ if (tv.tv_sec < timer->when) {
+ tv.tv_sec = timer->when;
+ tv.tv_usec = 0;
+ g_cond_timed_wait (timer_cond, mutex, &tv);
+ continue;
+ }
+#endif
}
/* Leave our thread mutex, and enter the module */
@@ -109,13 +123,22 @@ gkm_timer_initialize (void)
g_atomic_int_inc (&timer_refs);
if (!timer_thread) {
timer_run = TRUE;
+#if GLIB_CHECK_VERSION(2,31,3)
+ timer_thread = g_thread_new ("timer", timer_thread_func, NULL);
+#else
timer_thread = g_thread_create (timer_thread_func, NULL, TRUE, &error);
+#endif
if (timer_thread) {
g_assert (timer_queue == NULL);
timer_queue = g_queue_new ();
g_assert (timer_cond == NULL);
+#if GLIB_CHECK_VERSION(2,31,3)
+ timer_cond = &timer_condition;
+ g_cond_init (timer_cond);
+#else
timer_cond = g_cond_new ();
+#endif
} else {
g_warning ("could not create timer thread: %s",
egg_error_message (error));
@@ -155,7 +178,11 @@ gkm_timer_shutdown (void)
g_queue_free (timer_queue);
timer_queue = NULL;
+#if GLIB_CHECK_VERSION(2,31,3)
+ g_cond_clear (timer_cond);
+#else
g_cond_free (timer_cond);
+#endif
timer_cond = NULL;
}
}
diff --git a/pkcs11/gnome2-store/gkm-gnome2-standalone.c b/pkcs11/gnome2-store/gkm-gnome2-standalone.c
index 21ad2c68..631499c3 100644
--- a/pkcs11/gnome2-store/gkm-gnome2-standalone.c
+++ b/pkcs11/gnome2-store/gkm-gnome2-standalone.c
@@ -43,8 +43,6 @@ C_GetFunctionList (CK_FUNCTION_LIST_PTR_PTR list)
return CKR_ARGUMENTS_BAD;
g_type_init ();
- if (!g_thread_supported ())
- g_thread_init (NULL);
*list = gkm_gnome2_store_get_functions ();
return CKR_OK;
diff --git a/pkcs11/roots-store/gkm-roots-standalone.c b/pkcs11/roots-store/gkm-roots-standalone.c
index 469fb155..fb0f6427 100644
--- a/pkcs11/roots-store/gkm-roots-standalone.c
+++ b/pkcs11/roots-store/gkm-roots-standalone.c
@@ -59,9 +59,6 @@ C_GetFunctionList (CK_FUNCTION_LIST_PTR_PTR list)
g_type_init ();
- if (!g_thread_supported ())
- g_thread_init (NULL);
-
gkm_crypto_initialize ();
*list = gkm_roots_store_get_functions ();
diff --git a/pkcs11/rpc-layer/gkm-rpc-dispatch.c b/pkcs11/rpc-layer/gkm-rpc-dispatch.c
index a32043d9..d187148b 100644
--- a/pkcs11/rpc-layer/gkm-rpc-dispatch.c
+++ b/pkcs11/rpc-layer/gkm-rpc-dispatch.c
@@ -2229,7 +2229,11 @@ gkm_rpc_layer_accept (void)
ds->socket = new_fd;
+#if GLIB_CHECK_VERSION(2,31,3)
+ ds->thread = g_thread_new ("dispatch", run_dispatch_thread, &(ds->socket));
+#else
ds->thread = g_thread_create (run_dispatch_thread, &(ds->socket), TRUE, &error);
+#endif
if (!ds->thread) {
gkm_rpc_warn ("couldn't start thread: %s", egg_error_message (error));
close (new_fd);
diff --git a/pkcs11/secret-store/gkm-secret-standalone.c b/pkcs11/secret-store/gkm-secret-standalone.c
index 56b54e6c..70924b9c 100644
--- a/pkcs11/secret-store/gkm-secret-standalone.c
+++ b/pkcs11/secret-store/gkm-secret-standalone.c
@@ -59,9 +59,6 @@ C_GetFunctionList (CK_FUNCTION_LIST_PTR_PTR list)
g_type_init ();
- if (!g_thread_supported ())
- g_thread_init (NULL);
-
gkm_crypto_initialize ();
*list = gkm_secret_store_get_functions ();
diff --git a/pkcs11/ssh-store/gkm-ssh-standalone.c b/pkcs11/ssh-store/gkm-ssh-standalone.c
index a15bf0ef..0d7c10d8 100644
--- a/pkcs11/ssh-store/gkm-ssh-standalone.c
+++ b/pkcs11/ssh-store/gkm-ssh-standalone.c
@@ -58,8 +58,6 @@ C_GetFunctionList (CK_FUNCTION_LIST_PTR_PTR list)
return CKR_ARGUMENTS_BAD;
g_type_init ();
- if (!g_thread_supported ())
- g_thread_init (NULL);
*list = gkm_ssh_store_get_functions ();
return CKR_OK;
diff --git a/pkcs11/xdg-store/gkm-xdg-standalone.c b/pkcs11/xdg-store/gkm-xdg-standalone.c
index dc46dc25..dd1d3289 100644
--- a/pkcs11/xdg-store/gkm-xdg-standalone.c
+++ b/pkcs11/xdg-store/gkm-xdg-standalone.c
@@ -58,8 +58,6 @@ C_GetFunctionList (CK_FUNCTION_LIST_PTR_PTR list)
return CKR_ARGUMENTS_BAD;
g_type_init ();
- if (!g_thread_supported ())
- g_thread_init (NULL);
*list = gkm_xdg_store_get_functions ();
return CKR_OK;
diff --git a/tool/gkr-tool.c b/tool/gkr-tool.c
index 73aac6db..f783802d 100644
--- a/tool/gkr-tool.c
+++ b/tool/gkr-tool.c
@@ -116,8 +116,7 @@ main (int argc, char *argv[])
int ret = -1;
g_type_init ();
- g_thread_init (NULL);
-
+
#ifdef HAVE_LOCALE_H
/* internationalisation */
setlocale (LC_ALL, "");
diff --git a/ui/gku-prompt.c b/ui/gku-prompt.c
index 0a724245..c809272e 100644
--- a/ui/gku-prompt.c
+++ b/ui/gku-prompt.c
@@ -1093,7 +1093,15 @@ gku_prompt_request_attention_sync (const gchar *window_id, GkuPromptAttentionFun
gpointer user_data, GDestroyNotify destroy_notify)
{
AttentionReq *att = prepare_attention_req (window_id, callback, user_data, destroy_notify);
- GCond *cond = g_cond_new ();
+ GCond *cond;
+
+#if GLIB_CHECK_VERSION(2,31,3)
+ GCond condition;
+ g_cond_init (&condition);
+ cond = &condition;
+#else
+ cond = g_cond_new ();
+#endif
g_return_if_fail (att);
att->cond = cond;
@@ -1106,7 +1114,11 @@ gku_prompt_request_attention_sync (const gchar *window_id, GkuPromptAttentionFun
g_cond_wait (cond, g_static_mutex_get_mutex (&attention_mutex));
g_static_mutex_unlock (&attention_mutex);
+#if GLIB_CHECK_VERSION(2,31,3)
+ g_cond_clear (&condition);
+#else
g_cond_free (cond);
+#endif
}
#ifdef WITH_TESTABLE