diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-04-10 17:10:20 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-04-10 17:10:20 +0200 |
commit | 30d66bcebc27a1cdcbad39ddbeeaf047da6cc1dd (patch) | |
tree | b78ddf34d0360b2cf87037009d32dac0d3eaeb91 /src/exchange-tools/taler-exchange-dbinit.c | |
parent | 5fb65f59b2de184f4fcb1417923711bd64fe781a (diff) | |
download | exchange-30d66bcebc27a1cdcbad39ddbeeaf047da6cc1dd.tar.xz |
fixing #4386: use more sane configuration and data file structure
Diffstat (limited to 'src/exchange-tools/taler-exchange-dbinit.c')
-rw-r--r-- | src/exchange-tools/taler-exchange-dbinit.c | 46 |
1 files changed, 16 insertions, 30 deletions
diff --git a/src/exchange-tools/taler-exchange-dbinit.c b/src/exchange-tools/taler-exchange-dbinit.c index 43a070228..9f301854f 100644 --- a/src/exchange-tools/taler-exchange-dbinit.c +++ b/src/exchange-tools/taler-exchange-dbinit.c @@ -20,24 +20,8 @@ */ #include "platform.h" #include <gnunet/gnunet_util_lib.h> -#include <libpq-fe.h> #include "taler_exchangedb_plugin.h" -/** - * Exchange directory with the keys. - */ -static char *exchange_base_dir; - -/** - * Our configuration. - */ -static struct GNUNET_CONFIGURATION_Handle *cfg; - -/** - * Our DB plugin. - */ -static struct TALER_EXCHANGEDB_Plugin *plugin; - /** * The main function of the database initialization tool. @@ -51,14 +35,15 @@ int main (int argc, char *const *argv) { - static const struct GNUNET_GETOPT_CommandLineOption options[] = { - {'d', "exchange-dir", "DIR", - "exchange directory", 1, - &GNUNET_GETOPT_set_filename, &exchange_base_dir}, + char *cfgfile = NULL; + 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 }; + struct GNUNET_CONFIGURATION_Handle *cfg; + struct TALER_EXCHANGEDB_Plugin *plugin; if (GNUNET_GETOPT_run ("taler-exchange-dbinit", options, @@ -69,24 +54,23 @@ main (int argc, GNUNET_log_setup ("taler-exchange-dbinit", "INFO", NULL)); - if (NULL == exchange_base_dir) + cfg = GNUNET_CONFIGURATION_create (); + if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, + cfgfile)) { - fprintf (stderr, - "Exchange base directory not given.\n"); - return 1; - } - cfg = TALER_config_load (exchange_base_dir); - if (NULL == cfg) - { - fprintf (stderr, - "Failed to load exchange configuration.\n"); + 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 != @@ -96,9 +80,11 @@ main (int argc, fprintf (stderr, "Failed to initialize database.\n"); TALER_EXCHANGEDB_plugin_unload (plugin); + GNUNET_CONFIGURATION_destroy (cfg); return 1; } TALER_EXCHANGEDB_plugin_unload (plugin); + GNUNET_CONFIGURATION_destroy (cfg); return 0; } |