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 static void
run (void *cls, run (void *cls,
char *const *args, const struct GNUNET_SCHEDULER_TaskContext *tc)
const char *cfgfile,
const struct GNUNET_CONFIGURATION_Handle *config)
{ {
ctx = TALER_MINT_init (); ctx = TALER_MINT_init ();
GNUNET_assert (NULL != ctx); GNUNET_assert (NULL != ctx);
ctx_task = GNUNET_SCHEDULER_add_now (&context_task, ctx_task = GNUNET_SCHEDULER_add_now (&context_task,
ctx); ctx);
mint = TALER_MINT_connect (ctx, mint = TALER_MINT_connect (ctx,
"http://localhost:8080", "http://localhost:8081",
&cert_cb, NULL, &cert_cb, NULL,
TALER_MINT_OPTION_END); TALER_MINT_OPTION_END);
GNUNET_assert (NULL != mint); GNUNET_assert (NULL != mint);
@ -206,17 +204,26 @@ int
main (int argc, main (int argc,
char * const *argv) char * const *argv)
{ {
static struct GNUNET_GETOPT_CommandLineOption options[] = { struct GNUNET_OS_Process *mintd;
GNUNET_GETOPT_OPTION_END
};
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; result = GNUNET_SYSERR;
if (GNUNET_OK != GNUNET_SCHEDULER_run (&run, NULL);
GNUNET_PROGRAM_run (argc, argv, "test-mint-api", sleep (60);
gettext_noop ("Testcase to test mint's HTTP API interface"), GNUNET_OS_process_kill (mintd,
options, SIGTERM);
&run, NULL)) GNUNET_OS_process_wait (mintd);
return 3; GNUNET_OS_process_destroy (mintd);
return (GNUNET_OK == result) ? 0 : 1; 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). * 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 * @param key_state the key state to release
*/ */
void 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); GNUNET_assert (0 < key_state->refcnt);
key_state->refcnt--; key_state->refcnt--;
if (0 == 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->keys_json);
GNUNET_free (key_state); 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)); GNUNET_assert (0 == pthread_mutex_unlock (&internal_key_state_mutex));
} }
@ -462,7 +475,7 @@ TMH_KS_acquire (void)
if ( (NULL != internal_key_state) && if ( (NULL != internal_key_state) &&
(internal_key_state->next_reload.abs_value_us <= now.abs_value_us) ) (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; internal_key_state = NULL;
} }
if (NULL == internal_key_state) if (NULL == internal_key_state)
@ -488,8 +501,10 @@ TMH_KS_acquire (void)
GNUNET_CRYPTO_hash_context_finish (key_state->hash_context, GNUNET_CRYPTO_hash_context_finish (key_state->hash_context,
&ks.hc); &ks.hc);
key_state->hash_context = NULL; key_state->hash_context = NULL;
TMH_KS_sign (&ks.purpose, GNUNET_assert (GNUNET_OK ==
&sig); 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); 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) if (0 == key_state->next_reload.abs_value_us)
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, GNUNET_log (GNUNET_ERROR_TYPE_ERROR,