Properly shutdown.

This commit is contained in:
Marcello Stanisci 2019-02-12 16:06:37 +01:00
parent 1f007d83fd
commit 8aa66c6023
No known key found for this signature in database
GPG Key ID: 8D526861953F4C0F

View File

@ -82,6 +82,10 @@ void *since_when_bin;
*/ */
char *destination_account_url; char *destination_account_url;
/**
* Handle for the wire transfer preparation task.
*/
struct TALER_WIRE_PrepareHandle *ph;
/** /**
* Wire plugin handle. * Wire plugin handle.
@ -144,13 +148,19 @@ confirmation_cb (void *cls,
if (GNUNET_YES != success) if (GNUNET_YES != success)
{ {
fprintf (stderr, fprintf (stderr,
"The wire transfer didn't execute correctly\n"); "The wire transfer didn't execute correctly.\n");
GNUNET_assert (NULL != emsg); GNUNET_assert (NULL != emsg);
fprintf (stderr, fprintf (stderr,
emsg); emsg);
GNUNET_SCHEDULER_shutdown ();
return; return;
} }
fprintf (stdout,
"Wire transfer executed successfully.\n");
global_ret = 0; global_ret = 0;
GNUNET_SCHEDULER_shutdown ();
} }
@ -177,7 +187,16 @@ prepare_cb (void *cls,
{ {
fprintf (stderr, fprintf (stderr,
"Could not execute the wire transfer\n"); "Could not execute the wire transfer\n");
return;
plugin_handle->prepare_wire_transfer_cancel
(plugin_handle->cls,
ph);
plugin_handle->execute_wire_transfer_cancel
(plugin_handle->cls,
eh);
GNUNET_SCHEDULER_shutdown ();
} }
} }
@ -190,19 +209,23 @@ execute_wire_transfer ()
{ {
struct TALER_Amount a; struct TALER_Amount a;
struct TALER_WireTransferIdentifierRawP wtid; struct TALER_WireTransferIdentifierRawP wtid;
struct TALER_WIRE_PrepareHandle *ph;
/* Not the best thing to fail a assert here. */
GNUNET_assert (GNUNET_YES == transfer);
if (GNUNET_OK != TALER_string_to_amount (amount, if (GNUNET_OK != TALER_string_to_amount (amount,
&a)) &a))
{ {
fprintf (stderr, fprintf (stderr,
"Amount string incorrect.\n"); "Amount string incorrect.\n");
GNUNET_SCHEDULER_shutdown ();
return;
}
if (NULL == destination_account_url)
{
fprintf (stderr,
"Please give destination"
" account URL (--destination/-d)\n");
GNUNET_SCHEDULER_shutdown ();
return; return;
} }
if (NULL == (ph = plugin_handle->prepare_wire_transfer if (NULL == (ph = plugin_handle->prepare_wire_transfer
(plugin_handle->cls, (plugin_handle->cls,
account_section, account_section,
@ -215,11 +238,8 @@ execute_wire_transfer ()
{ {
fprintf (stderr, fprintf (stderr,
"Could not prepare the wire transfer\n"); "Could not prepare the wire transfer\n");
return; GNUNET_SCHEDULER_shutdown ();
} }
plugin_handle->prepare_wire_transfer_cancel (plugin_handle->cls,
ph);
} }
/** /**
@ -235,6 +255,7 @@ execute_history ()
{ {
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Missing since-when option\n"); "Missing since-when option\n");
GNUNET_SCHEDULER_shutdown ();
return; return;
} }
@ -258,11 +279,24 @@ execute_history ()
{ {
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Could not request the transaction history.\n"); "Could not request the transaction history.\n");
GNUNET_SCHEDULER_shutdown ();
return; return;
} }
} }
/**
* Gets executed upon shutdown. Main duty is
* wire-plugin unloading.
*
* @param cls closure.
*/
void
do_shutdown (void *cls)
{
TALER_WIRE_plugin_unload (plugin_handle);
}
/** /**
* Main function that will be run. * Main function that will be run.
* *
@ -313,6 +347,9 @@ run (void *cls,
else else
fprintf (stderr, fprintf (stderr,
"Please give either --history/-H or --transfer/t\n"); "Please give either --history/-H or --transfer/t\n");
GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
NULL);
} }
/** /**
@ -333,7 +370,8 @@ main (int argc,
GNUNET_GETOPT_option_flag ('H', GNUNET_GETOPT_option_flag ('H',
"history", "history",
"Ask to get the list of transactions.", "Ask to get the list of"
" transactions.",
&history), &history),
GNUNET_GETOPT_option_flag ('t', GNUNET_GETOPT_option_flag ('t',
@ -378,16 +416,14 @@ main (int argc,
(GNUNET_OK == GNUNET_log_setup ("taler-wire", (GNUNET_OK == GNUNET_log_setup ("taler-wire",
NULL, NULL,
NULL)); /* filename */ NULL)); /* filename */
GNUNET_PROGRAM_run
if (GNUNET_OK != GNUNET_PROGRAM_run
(argc, (argc,
argv, argv,
"taler-wire", "taler-wire",
"CLI bank client.", "CLI bank client.",
options, options,
&run, &run,
NULL)) NULL);
return 1;
return global_ret; return global_ret;
} }