fix a few pointer passing issues, add remark about #3886

This commit is contained in:
Christian Grothoff 2015-07-09 22:10:14 +02:00
parent be778784ea
commit be535b68e1
8 changed files with 173 additions and 60 deletions

View File

@ -105,6 +105,7 @@ handle_mhd_completion_callback (void *cls,
void **con_cls, void **con_cls,
enum MHD_RequestTerminationCode toe) enum MHD_RequestTerminationCode toe)
{ {
fprintf (stderr, "CC called (%p)!\n", *con_cls);
if (NULL == *con_cls) if (NULL == *con_cls)
return; return;
TMH_PARSE_post_cleanup_callback (*con_cls); TMH_PARSE_post_cleanup_callback (*con_cls);
@ -482,9 +483,32 @@ main (int argc, char *const *argv)
"Failed to start HTTP server.\n"); "Failed to start HTTP server.\n");
return 1; return 1;
} }
ret = TMH_KS_loop (); ret = TMH_KS_loop ();
switch (ret)
{
case GNUNET_OK:
case GNUNET_SYSERR:
MHD_stop_daemon (mydaemon); MHD_stop_daemon (mydaemon);
break;
case GNUNET_NO:
{
MHD_socket sock = MHD_quiesce_daemon (mydaemon);
/* FIXME #3474: fork another MHD, passing on the listen socket! */
while (0 != MHD_get_daemon_info (mydaemon,
MHD_DAEMON_INFO_CURRENT_CONNECTIONS)->num_connections)
sleep (1);
MHD_stop_daemon (mydaemon);
close (sock); /* FIXME: done like this because #3474 is open */
}
break;
default:
GNUNET_break (0);
MHD_stop_daemon (mydaemon);
break;
}
if (GNUNET_YES == TMH_test_mode) if (GNUNET_YES == TMH_test_mode)
{ {
struct TALER_MINTDB_Session *session; struct TALER_MINTDB_Session *session;
@ -499,5 +523,5 @@ main (int argc, char *const *argv)
} }
TALER_MINTDB_plugin_unload (TMH_plugin); TALER_MINTDB_plugin_unload (TMH_plugin);
return (GNUNET_OK == ret) ? 0 : 1; return (GNUNET_SYSERR == ret) ? 1 : 0;
} }

View File

@ -296,6 +296,8 @@ reload_keys_denom_iter (void *cls,
as it is possible we just retry until we succeed. */ as it is possible we just retry until we succeed. */
} }
/* FIXME: this is a VERY ugly (we obtain ownership of
pointers within 'dki' here!!!) #3886 */
d2 = GNUNET_memdup (dki, d2 = GNUNET_memdup (dki,
sizeof (struct TALER_MINTDB_DenominationKeyIssueInformation)); sizeof (struct TALER_MINTDB_DenominationKeyIssueInformation));
res = GNUNET_CONTAINER_multihashmap_put (ctx->denomkey_map, res = GNUNET_CONTAINER_multihashmap_put (ctx->denomkey_map,
@ -418,6 +420,8 @@ free_denom_key (void *cls,
{ {
struct TALER_MINTDB_DenominationKeyIssueInformation *dki = value; struct TALER_MINTDB_DenominationKeyIssueInformation *dki = value;
GNUNET_CRYPTO_rsa_private_key_free (dki->denom_priv.rsa_private_key);
GNUNET_CRYPTO_rsa_public_key_free (dki->denom_pub.rsa_public_key);
GNUNET_free (dki); GNUNET_free (dki);
return GNUNET_OK; return GNUNET_OK;
} }
@ -435,14 +439,26 @@ TMH_KS_release_ (struct TMH_KS_StateHandle *key_state)
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)
{
if (NULL != key_state->denom_keys_array)
{ {
json_decref (key_state->denom_keys_array); json_decref (key_state->denom_keys_array);
key_state->denom_keys_array = NULL;
}
if (NULL != key_state->sign_keys_array)
{
json_decref (key_state->sign_keys_array); json_decref (key_state->sign_keys_array);
key_state->sign_keys_array = NULL;
}
if (NULL != key_state->denomkey_map)
{
GNUNET_CONTAINER_multihashmap_iterate (key_state->denomkey_map, GNUNET_CONTAINER_multihashmap_iterate (key_state->denomkey_map,
&free_denom_key, &free_denom_key,
key_state); key_state);
GNUNET_CONTAINER_multihashmap_destroy (key_state->denomkey_map); GNUNET_CONTAINER_multihashmap_destroy (key_state->denomkey_map);
GNUNET_free (key_state->keys_json); key_state->denomkey_map = NULL;
}
GNUNET_free_non_null (key_state->keys_json);
GNUNET_free (key_state); GNUNET_free (key_state);
} }
} }
@ -532,6 +548,8 @@ TMH_KS_acquire (void)
sizeof (struct TALER_MintPublicKeyP)), sizeof (struct TALER_MintPublicKeyP)),
"eddsa_sig", TALER_json_from_data (&sig, "eddsa_sig", TALER_json_from_data (&sig,
sizeof (struct TALER_MintSignatureP))); sizeof (struct TALER_MintSignatureP)));
key_state->sign_keys_array = NULL;
key_state->denom_keys_array = NULL;
key_state->keys_json = json_dumps (keys, key_state->keys_json = json_dumps (keys,
JSON_INDENT (2)); JSON_INDENT (2));
json_decref (keys); json_decref (keys);
@ -605,8 +623,7 @@ TMH_KS_denomination_key_lookup (const struct TMH_KS_StateHandle *key_state,
/** /**
* Handle a signal, writing relevant signal numbers * Handle a signal, writing relevant signal numbers to the pipe.
* (currently just SIGUSR1) to a pipe.
* *
* @param signal_number the signal number * @param signal_number the signal number
*/ */
@ -616,8 +633,6 @@ handle_signal (int signal_number)
ssize_t res; ssize_t res;
char c = signal_number; char c = signal_number;
if (SIGUSR1 == signal_number)
{
res = write (reload_pipe[1], res = write (reload_pipe[1],
&c, &c,
1); 1);
@ -633,21 +648,68 @@ handle_signal (int signal_number)
return; return;
} }
} }
/**
* Call #handle_signal() to pass the received signal via
* the control pipe.
*/
static void
handle_sigusr1 ()
{
handle_signal (SIGUSR1);
}
/**
* Call #handle_signal() to pass the received signal via
* the control pipe.
*/
static void
handle_sigint ()
{
handle_signal (SIGINT);
}
/**
* Call #handle_signal() to pass the received signal via
* the control pipe.
*/
static void
handle_sigterm ()
{
handle_signal (SIGTERM);
}
/**
* Call #handle_signal() to pass the received signal via
* the control pipe.
*/
static void
handle_sighup ()
{
handle_signal (SIGHUP);
} }
/** /**
* Read signals from a pipe in a loop, and reload keys from disk if * Read signals from a pipe in a loop, and reload keys from disk if
* SIGUSR1 is read from the pipe. * SIGUSR1 is received, terminate if SIGTERM/SIGINT is received, and
* restart if SIGHUP is received.
* *
* @return #GNUNET_SYSERR on errors, otherwise does not return * @return #GNUNET_SYSERR on errors,
* (FIXME: #3474) * #GNUNET_OK to terminate normally
* #GNUNET_NO to restart an update version of the binary
*/ */
int int
TMH_KS_loop (void) TMH_KS_loop (void)
{ {
struct sigaction act; struct GNUNET_SIGNAL_Context *sigusr1;
struct sigaction rec; struct GNUNET_SIGNAL_Context *sigterm;
struct GNUNET_SIGNAL_Context *sigint;
struct GNUNET_SIGNAL_Context *sighup;
int ret; int ret;
if (0 != pipe (reload_pipe)) if (0 != pipe (reload_pipe))
@ -656,22 +718,17 @@ TMH_KS_loop (void)
"Failed to create pipe.\n"); "Failed to create pipe.\n");
return GNUNET_SYSERR; return GNUNET_SYSERR;
} }
memset (&act, sigusr1 = GNUNET_SIGNAL_handler_install (SIGUSR1,
0, &handle_sigusr1);
sizeof (struct sigaction)); sigterm = GNUNET_SIGNAL_handler_install (SIGTERM,
act.sa_handler = &handle_signal; &handle_sigterm);
if (0 != sigaction (SIGUSR1, sigint = GNUNET_SIGNAL_handler_install (SIGINT,
&act, &handle_sigint);
&rec)) sighup = GNUNET_SIGNAL_handler_install (SIGHUP,
{ &handle_sighup);
fprintf (stderr,
"Failed to set signal handler.\n");
return GNUNET_SYSERR;
}
ret = GNUNET_OK; ret = 0;
/* FIXME: allow for 'clean' termination or restart (#3474) */ while (0 == ret)
while (1)
{ {
char c; char c;
ssize_t res; ssize_t res;
@ -700,16 +757,35 @@ read_again:
} }
if (EINTR == errno) if (EINTR == errno)
goto read_again; goto read_again;
} switch (c)
if (0 != sigaction (SIGUSR1,
&rec,
&act))
{ {
fprintf (stderr, case SIGUSR1:
"Failed to restore signal handler.\n"); /* reload internal key state, we do this in the loop */
return GNUNET_SYSERR; break;
case SIGTERM:
case SIGINT:
/* terminate */
ret = GNUNET_OK;
break;
case SIGHUP:
/* restart updated binary */
ret = GNUNET_NO;
break;
default:
/* unexpected character */
GNUNET_break (0);
break;
} }
}
if (NULL != internal_key_state)
{
TMH_KS_release (internal_key_state);
internal_key_state = NULL;
}
GNUNET_SIGNAL_handler_uninstall (sigusr1);
GNUNET_SIGNAL_handler_uninstall (sigterm);
GNUNET_SIGNAL_handler_uninstall (sigint);
GNUNET_SIGNAL_handler_uninstall (sighup);
return ret; return ret;
} }

View File

@ -96,10 +96,12 @@ TMH_KS_denomination_key_lookup (const struct TMH_KS_StateHandle *key_state,
/** /**
* Read signals from a pipe in a loop, and reload keys from disk if * Read signals from a pipe in a loop, and reload keys from disk if
* SIGUSR1 is read from the pipe. * SIGUSR1 is received, terminate if SIGTERM/SIGINT is received, and
* restart if SIGHUP is received.
* *
* @return #GNUNET_OK if we terminated normally, * @return #GNUNET_SYSERR on errors,
* #GNUNET_SYSERR on error * #GNUNET_OK to terminate normally
* #GNUNET_NO to restart an update version of the binary
*/ */
int int
TMH_KS_loop (void); TMH_KS_loop (void);

View File

@ -273,6 +273,7 @@ TMH_PARSE_post_json (struct MHD_Connection *connection,
? GNUNET_SYSERR : GNUNET_NO; ? GNUNET_SYSERR : GNUNET_NO;
} }
/* everything OK, wait for more POST data */ /* everything OK, wait for more POST data */
fprintf (stderr, "Init %p\n", r);
*upload_data_size = 0; *upload_data_size = 0;
*con_cls = r; *con_cls = r;
return GNUNET_YES; return GNUNET_YES;
@ -314,6 +315,8 @@ TMH_PARSE_post_json (struct MHD_Connection *connection,
TMH_RESPONSE_reply_invalid_json (connection)) TMH_RESPONSE_reply_invalid_json (connection))
? GNUNET_NO : GNUNET_SYSERR; ? GNUNET_NO : GNUNET_SYSERR;
} }
fprintf (stderr, "Deinit %p\n", r);
buffer_deinit (r); buffer_deinit (r);
GNUNET_free (r); GNUNET_free (r);
*con_cls = NULL; *con_cls = NULL;

View File

@ -525,7 +525,7 @@ compile_reserve_history (const struct TALER_MINTDB_ReserveHistory *rh,
} }
ret = 1; ret = 1;
json_array_append_new (json_history, json_array_append_new (json_history,
json_pack ("{s:s, s:o, s:o}", json_pack ("{s:s, s:O, s:o}",
"type", "DEPOSIT", "type", "DEPOSIT",
"wire", pos->details.bank->wire, "wire", pos->details.bank->wire,
"amount", TALER_json_from_amount (&pos->details.bank->amount))); "amount", TALER_json_from_amount (&pos->details.bank->amount)));

View File

@ -165,6 +165,7 @@ TALER_MINTDB_denomination_key_read (const char *filename,
GNUNET_free (data); GNUNET_free (data);
return GNUNET_SYSERR; return GNUNET_SYSERR;
} }
GNUNET_assert (NULL == dki->denom_priv.rsa_private_key);
dki->denom_priv.rsa_private_key = priv; dki->denom_priv.rsa_private_key = priv;
dki->denom_pub.rsa_public_key dki->denom_pub.rsa_public_key
= GNUNET_CRYPTO_rsa_private_key_get_public (priv); = GNUNET_CRYPTO_rsa_private_key_get_public (priv);
@ -270,6 +271,7 @@ denomkeys_iterate_keydir_iter (void *cls,
struct DenomkeysIterateContext *dic = cls; struct DenomkeysIterateContext *dic = cls;
struct TALER_MINTDB_DenominationKeyIssueInformation issue; struct TALER_MINTDB_DenominationKeyIssueInformation issue;
memset (&issue, 0, sizeof (issue));
if (GNUNET_OK != if (GNUNET_OK !=
TALER_MINTDB_denomination_key_read (filename, TALER_MINTDB_denomination_key_read (filename,
&issue)) &issue))
@ -279,6 +281,8 @@ denomkeys_iterate_keydir_iter (void *cls,
filename); filename);
return GNUNET_OK; return GNUNET_OK;
} }
/* FIXME: very ugly, 'it' is to free memory WE
allocated as part of issue!!?? #3886 */
return dic->it (dic->it_cls, return dic->it (dic->it_cls,
dic->alias, dic->alias,
&issue); &issue);

View File

@ -100,6 +100,8 @@ common_free_coin_transaction_list (void *cls,
{ {
case TALER_MINTDB_TT_DEPOSIT: case TALER_MINTDB_TT_DEPOSIT:
json_decref (list->details.deposit->wire); json_decref (list->details.deposit->wire);
GNUNET_CRYPTO_rsa_public_key_free (list->details.deposit->coin.denom_pub.rsa_public_key);
GNUNET_CRYPTO_rsa_signature_free (list->details.deposit->coin.denom_sig.rsa_signature);
GNUNET_free (list->details.deposit); GNUNET_free (list->details.deposit);
break; break;
case TALER_MINTDB_TT_REFRESH_MELT: case TALER_MINTDB_TT_REFRESH_MELT:

View File

@ -892,10 +892,12 @@ postgres_prepare (PGconn *db_conn)
static void static void
db_conn_destroy (void *cls) db_conn_destroy (void *cls)
{ {
PGconn *db_conn = cls; struct TALER_MINTDB_Session *session = cls;
PGconn *db_conn = session->conn;
if (NULL != db_conn) if (NULL != db_conn)
PQfinish (db_conn); PQfinish (db_conn);
GNUNET_free (session);
} }