fix locking issue, as the mutex we are using is not recursive we need to be a bit more careful

This commit is contained in:
Christian Grothoff 2015-06-18 13:44:58 +02:00
parent 740d6cba04
commit d15c654749
2 changed files with 40 additions and 18 deletions

View File

@ -176,16 +176,14 @@ context_task (void *cls,
*/
static void
run (void *cls,
char *const *args,
const char *cfgfile,
const struct GNUNET_CONFIGURATION_Handle *config)
const struct GNUNET_SCHEDULER_TaskContext *tc)
{
ctx = TALER_MINT_init ();
GNUNET_assert (NULL != ctx);
ctx_task = GNUNET_SCHEDULER_add_now (&context_task,
ctx);
mint = TALER_MINT_connect (ctx,
"http://localhost:8080",
"http://localhost:8081",
&cert_cb, NULL,
TALER_MINT_OPTION_END);
GNUNET_assert (NULL != mint);
@ -206,17 +204,26 @@ int
main (int argc,
char * const *argv)
{
static struct GNUNET_GETOPT_CommandLineOption options[] = {
GNUNET_GETOPT_OPTION_END
};
struct GNUNET_OS_Process *mintd;
GNUNET_log_setup ("test-mint-api",
"WARNING",
NULL);
mintd = GNUNET_OS_start_process (GNUNET_NO,
GNUNET_OS_INHERIT_STD_ALL,
NULL, NULL, NULL,
"taler-mint-httpd",
"taler-mint-httpd",
"-d", "test-mint-home",
NULL);
sleep (1);
result = GNUNET_SYSERR;
if (GNUNET_OK !=
GNUNET_PROGRAM_run (argc, argv, "test-mint-api",
gettext_noop ("Testcase to test mint's HTTP API interface"),
options,
&run, NULL))
return 3;
GNUNET_SCHEDULER_run (&run, NULL);
sleep (60);
GNUNET_OS_process_kill (mintd,
SIGTERM);
GNUNET_OS_process_wait (mintd);
GNUNET_OS_process_destroy (mintd);
return (GNUNET_OK == result) ? 0 : 1;
}

View File

@ -418,13 +418,13 @@ free_denom_key (void *cls,
/**
* Release key state, free if necessary (if reference count gets to zero).
* Internal method used when the mutex is already held.
*
* @param key_state the key state to release
*/
void
TMH_KS_release (struct TMH_KS_StateHandle *key_state)
TMH_KS_release_ (struct TMH_KS_StateHandle *key_state)
{
GNUNET_assert (0 == pthread_mutex_lock (&internal_key_state_mutex));
GNUNET_assert (0 < key_state->refcnt);
key_state->refcnt--;
if (0 == key_state->refcnt)
@ -438,6 +438,19 @@ TMH_KS_release (struct TMH_KS_StateHandle *key_state)
GNUNET_free (key_state->keys_json);
GNUNET_free (key_state);
}
}
/**
* Release key state, free if necessary (if reference count gets to zero).
*
* @param key_state the key state to release
*/
void
TMH_KS_release (struct TMH_KS_StateHandle *key_state)
{
GNUNET_assert (0 == pthread_mutex_lock (&internal_key_state_mutex));
TMH_KS_release_ (key_state);
GNUNET_assert (0 == pthread_mutex_unlock (&internal_key_state_mutex));
}
@ -462,7 +475,7 @@ TMH_KS_acquire (void)
if ( (NULL != internal_key_state) &&
(internal_key_state->next_reload.abs_value_us <= now.abs_value_us) )
{
TMH_KS_release (internal_key_state);
TMH_KS_release_ (internal_key_state);
internal_key_state = NULL;
}
if (NULL == internal_key_state)
@ -488,8 +501,10 @@ TMH_KS_acquire (void)
GNUNET_CRYPTO_hash_context_finish (key_state->hash_context,
&ks.hc);
key_state->hash_context = NULL;
TMH_KS_sign (&ks.purpose,
&sig);
GNUNET_assert (GNUNET_OK ==
GNUNET_CRYPTO_eddsa_sign (&key_state->current_sign_key_issue.signkey_priv.eddsa_priv,
&ks.purpose,
&sig.eddsa_signature));
key_state->next_reload = GNUNET_TIME_absolute_ntoh (key_state->current_sign_key_issue.issue.expire);
if (0 == key_state->next_reload.abs_value_us)
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,