Merge branch 'master' of git+ssh://taler.net/var/git/exchange

This commit is contained in:
Christian Grothoff 2016-04-17 16:28:50 +02:00
commit 05751b63aa
3 changed files with 58 additions and 41 deletions

View File

@ -23,6 +23,50 @@
#include "taler_exchangedb_plugin.h" #include "taler_exchangedb_plugin.h"
/**
* Return value from main().
*/
static int global_ret;
/**
* Main function that will be run.
*
* @param cls closure
* @param args remaining command-line arguments
* @param cfgfile name of the configuration file used (for saving, can be NULL!)
* @param cfg configuration
*/
static void
run (void *cls,
char *const *args,
const char *cfgfile,
const struct GNUNET_CONFIGURATION_Handle *cfg)
{
struct TALER_EXCHANGEDB_Plugin *plugin;
if (NULL ==
(plugin = TALER_EXCHANGEDB_plugin_load (cfg)))
{
fprintf (stderr,
"Failed to initialize database plugin.\n");
global_ret = 1;
return;
}
if (GNUNET_OK !=
plugin->create_tables (plugin->cls,
GNUNET_NO))
{
fprintf (stderr,
"Failed to initialize database.\n");
TALER_EXCHANGEDB_plugin_unload (plugin);
global_ret = 1;
return;
}
TALER_EXCHANGEDB_plugin_unload (plugin);
}
/** /**
* The main function of the database initialization tool. * The main function of the database initialization tool.
* Used to initialize the Taler Exchange's database. * Used to initialize the Taler Exchange's database.
@ -35,57 +79,27 @@ int
main (int argc, main (int argc,
char *const *argv) char *const *argv)
{ {
char *cfgfile = NULL;
const struct GNUNET_GETOPT_CommandLineOption options[] = { const struct GNUNET_GETOPT_CommandLineOption options[] = {
GNUNET_GETOPT_OPTION_CFG_FILE (&cfgfile),
GNUNET_GETOPT_OPTION_HELP ("Initialize Taler Exchange database"),
GNUNET_GETOPT_OPTION_VERSION (VERSION "-" VCS_VERSION),
GNUNET_GETOPT_OPTION_END GNUNET_GETOPT_OPTION_END
}; };
struct GNUNET_CONFIGURATION_Handle *cfg;
struct TALER_EXCHANGEDB_Plugin *plugin;
if (GNUNET_GETOPT_run ("taler-exchange-dbinit",
options,
argc, argv) < 0)
return 1;
/* force linker to link against libtalerutil; if we do
not do this, the linker may "optimize" libtalerutil
away and skip #TALER_OS_init(), which we do need */
(void) TALER_project_data_default ();
GNUNET_assert (GNUNET_OK == GNUNET_assert (GNUNET_OK ==
GNUNET_log_setup ("taler-exchange-dbinit", GNUNET_log_setup ("taler-exchange-dbinit",
"INFO", "INFO",
NULL)); NULL));
cfg = GNUNET_CONFIGURATION_create ();
if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg,
cfgfile))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
_("Malformed configuration file `%s', exit ...\n"),
cfgfile);
GNUNET_free_non_null (cfgfile);
return 1;
}
GNUNET_free_non_null (cfgfile);
if (NULL ==
(plugin = TALER_EXCHANGEDB_plugin_load (cfg)))
{
fprintf (stderr,
"Failed to initialize database plugin.\n");
GNUNET_CONFIGURATION_destroy (cfg);
return 1;
}
if (GNUNET_OK != if (GNUNET_OK !=
plugin->create_tables (plugin->cls, GNUNET_PROGRAM_run (argc, argv,
GNUNET_NO)) "taler-exchange-dbinit",
{ "Initialize Taler exchange database",
fprintf (stderr, options,
"Failed to initialize database.\n"); &run, NULL))
TALER_EXCHANGEDB_plugin_unload (plugin);
GNUNET_CONFIGURATION_destroy (cfg);
return 1; return 1;
} return global_ret;
TALER_EXCHANGEDB_plugin_unload (plugin);
GNUNET_CONFIGURATION_destroy (cfg);
return 0;
} }
/* end of taler-exchange-dbinit.c */ /* end of taler-exchange-dbinit.c */

View File

@ -41,6 +41,7 @@ static const struct GNUNET_CONFIGURATION_Handle *kcfg;
*/ */
static int global_ret; static int global_ret;
/** /**
* Function called on each signing key. * Function called on each signing key.
* *

View File

@ -648,6 +648,8 @@ main (int argc,
options, options,
argc, argv)) argc, argv))
return 1; return 1;
if (NULL == cfgfile)
cfgfile = GNUNET_strdup (GNUNET_OS_project_data_get ()->user_config_file);
cfg = GNUNET_CONFIGURATION_create (); cfg = GNUNET_CONFIGURATION_create ();
if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, cfgfile)) if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, cfgfile))
{ {