fix config parsing for dbinit tool
This commit is contained in:
parent
a34891981c
commit
719b51b65d
@ -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,23 @@ 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;
|
|
||||||
|
|
||||||
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 */
|
||||||
|
@ -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))
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user