avoid duping configuration, start to use PQ_connect_with_cfg

This commit is contained in:
Christian Grothoff 2020-02-09 15:53:28 +01:00
parent 001f155208
commit ae5583f044
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC
4 changed files with 16 additions and 14 deletions

View File

@ -35,7 +35,6 @@ TALER_AUDITORDB_plugin_load (const struct GNUNET_CONFIGURATION_Handle *cfg)
{ {
char *plugin_name; char *plugin_name;
char *lib_name; char *lib_name;
struct GNUNET_CONFIGURATION_Handle *cfg_dup;
struct TALER_AUDITORDB_Plugin *plugin; struct TALER_AUDITORDB_Plugin *plugin;
if (GNUNET_SYSERR == if (GNUNET_SYSERR ==
@ -53,14 +52,12 @@ TALER_AUDITORDB_plugin_load (const struct GNUNET_CONFIGURATION_Handle *cfg)
"libtaler_plugin_auditordb_%s", "libtaler_plugin_auditordb_%s",
plugin_name); plugin_name);
GNUNET_free (plugin_name); GNUNET_free (plugin_name);
cfg_dup = GNUNET_CONFIGURATION_dup (cfg);
plugin = GNUNET_PLUGIN_load (lib_name, plugin = GNUNET_PLUGIN_load (lib_name,
cfg_dup); (void *) cfg);
if (NULL != plugin) if (NULL != plugin)
plugin->library_name = lib_name; plugin->library_name = lib_name;
else else
GNUNET_free (lib_name); GNUNET_free (lib_name);
GNUNET_CONFIGURATION_destroy (cfg_dup);
return plugin; return plugin;
} }

View File

@ -3244,7 +3244,7 @@ postgres_get_predicted_balance (void *cls,
void * void *
libtaler_plugin_auditordb_postgres_init (void *cls) libtaler_plugin_auditordb_postgres_init (void *cls)
{ {
struct GNUNET_CONFIGURATION_Handle *cfg = cls; const struct GNUNET_CONFIGURATION_Handle *cfg = cls;
struct PostgresClosure *pg; struct PostgresClosure *pg;
struct TALER_AUDITORDB_Plugin *plugin; struct TALER_AUDITORDB_Plugin *plugin;
const char *ec; const char *ec;

View File

@ -35,7 +35,6 @@ TALER_EXCHANGEDB_plugin_load (const struct GNUNET_CONFIGURATION_Handle *cfg)
{ {
char *plugin_name; char *plugin_name;
char *lib_name; char *lib_name;
struct GNUNET_CONFIGURATION_Handle *cfg_dup;
struct TALER_EXCHANGEDB_Plugin *plugin; struct TALER_EXCHANGEDB_Plugin *plugin;
if (GNUNET_SYSERR == if (GNUNET_SYSERR ==
@ -53,13 +52,12 @@ TALER_EXCHANGEDB_plugin_load (const struct GNUNET_CONFIGURATION_Handle *cfg)
"libtaler_plugin_exchangedb_%s", "libtaler_plugin_exchangedb_%s",
plugin_name); plugin_name);
GNUNET_free (plugin_name); GNUNET_free (plugin_name);
cfg_dup = GNUNET_CONFIGURATION_dup (cfg); plugin = GNUNET_PLUGIN_load (lib_name,
plugin = GNUNET_PLUGIN_load (lib_name, cfg_dup); (void *) cfg);
if (NULL != plugin) if (NULL != plugin)
plugin->library_name = lib_name; plugin->library_name = lib_name;
else else
GNUNET_free (lib_name); GNUNET_free (lib_name);
GNUNET_CONFIGURATION_destroy (cfg_dup);
return plugin; return plugin;
} }

View File

@ -108,6 +108,11 @@ struct PostgresClosure
*/ */
pthread_key_t db_conn_threadlocal; pthread_key_t db_conn_threadlocal;
/**
* Our configuration.
*/
const struct GNUNET_CONFIGURATION_Handle *cfg;
/** /**
* Database connection string, as read from * Database connection string, as read from
* the configuration. * the configuration.
@ -187,8 +192,9 @@ postgres_create_tables (void *cls)
struct PostgresClosure *pc = cls; struct PostgresClosure *pc = cls;
struct GNUNET_PQ_Context *conn; struct GNUNET_PQ_Context *conn;
conn = GNUNET_PQ_connect (pc->connection_cfg_str, conn = GNUNET_PQ_connect_with_cfg (pc->cfg,
pc->sql_dir, "exchangedb-postgres",
"",
NULL, NULL,
NULL); NULL);
if (NULL == conn) if (NULL == conn)
@ -7212,12 +7218,13 @@ postgres_select_deposits_missing_wire (void *cls,
void * void *
libtaler_plugin_exchangedb_postgres_init (void *cls) libtaler_plugin_exchangedb_postgres_init (void *cls)
{ {
struct GNUNET_CONFIGURATION_Handle *cfg = cls; const struct GNUNET_CONFIGURATION_Handle *cfg = cls;
struct PostgresClosure *pg; struct PostgresClosure *pg;
struct TALER_EXCHANGEDB_Plugin *plugin; struct TALER_EXCHANGEDB_Plugin *plugin;
const char *ec; const char *ec;
pg = GNUNET_new (struct PostgresClosure); pg = GNUNET_new (struct PostgresClosure);
pg->cfg = cfg;
pg->main_self = pthread_self (); /* loaded while single-threaded! */ pg->main_self = pthread_self (); /* loaded while single-threaded! */
if (GNUNET_OK != if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_filename (cfg, GNUNET_CONFIGURATION_get_value_filename (cfg,