From: Christian Grothoff Date: Tue, 11 Oct 2016 13:45:37 +0000 (+0000) Subject: proper bail out if plugin loading fails X-Git-Tag: initial-import-from-subversion-38251~131 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=7e5d16c7dc211c0682b38deaa3bfa108b0b07bb3;p=oweals%2Fgnunet.git proper bail out if plugin loading fails --- diff --git a/src/psycstore/plugin_psycstore_mysql.c b/src/psycstore/plugin_psycstore_mysql.c index d857262d6..73f55186b 100644 --- a/src/psycstore/plugin_psycstore_mysql.c +++ b/src/psycstore/plugin_psycstore_mysql.c @@ -101,7 +101,6 @@ struct Plugin */ struct GNUNET_MYSQL_StatementHandle *insert_channel_key; - /** * Precompiled SQL for slave_key_store() */ @@ -268,50 +267,58 @@ mysql_prepare (struct GNUNET_MYSQL_Context *mc, * as needed as well). * * @param plugin the plugin context (state for this module) - * @return GNUNET_OK on success + * @return #GNUNET_OK on success */ static int database_setup (struct Plugin *plugin) { /* Open database and precompile statements */ - plugin->mc = GNUNET_MYSQL_context_create (plugin->cfg, "psycstore-mysql"); + plugin->mc = GNUNET_MYSQL_context_create (plugin->cfg, + "psycstore-mysql"); if (NULL == plugin->mc) { - LOG(GNUNET_ERROR_TYPE_ERROR, - _("Unable to initialize Mysql.\n")); + LOG (GNUNET_ERROR_TYPE_ERROR, + _("Unable to initialize Mysql.\n")); return GNUNET_SYSERR; } - /* Create tables */ - - GNUNET_MYSQL_statement_run (plugin->mc, - "CREATE TABLE IF NOT EXISTS channels (\n" - " id INT AUTO_INCREMENT,\n" - " pub_key BLOB,\n" - " max_state_message_id INT,\n" - " state_hash_message_id INT,\n" - " PRIMARY KEY(id),\n" - " UNIQUE KEY(pub_key(5))\n" - ");"); - - GNUNET_MYSQL_statement_run (plugin->mc, - "CREATE TABLE IF NOT EXISTS slaves (\n" - " id INT AUTO_INCREMENT,\n" - " pub_key BLOB,\n" - " PRIMARY KEY(id),\n" - " UNIQUE KEY(pub_key(5))\n" - ");"); +#define STMT_RUN(sql) \ + if (GNUNET_OK != \ + GNUNET_MYSQL_statement_run (plugin->mc, \ + sql)) \ + { \ + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \ + _("Failed to run SQL statement `%s'\n"), \ + sql); \ + return GNUNET_SYSERR; \ + } - GNUNET_MYSQL_statement_run (plugin->mc, - "CREATE TABLE IF NOT EXISTS membership (\n" - " channel_id INT NOT NULL REFERENCES channels(id),\n" - " slave_id INT NOT NULL REFERENCES slaves(id),\n" - " did_join INT NOT NULL,\n" - " announced_at BIGINT UNSIGNED NOT NULL,\n" - " effective_since BIGINT UNSIGNED NOT NULL,\n" - " group_generation BIGINT UNSIGNED NOT NULL\n" - ");"); + /* Create tables */ + STMT_RUN ("CREATE TABLE IF NOT EXISTS channels (\n" + " id INT AUTO_INCREMENT,\n" + " pub_key BLOB,\n" + " max_state_message_id INT,\n" + " state_hash_message_id INT,\n" + " PRIMARY KEY(id),\n" + " UNIQUE KEY(pub_key(5))\n" + ");"); + + STMT_RUN ("CREATE TABLE IF NOT EXISTS slaves (\n" + " id INT AUTO_INCREMENT,\n" + " pub_key BLOB,\n" + " PRIMARY KEY(id),\n" + " UNIQUE KEY(pub_key(5))\n" + ");"); + + STMT_RUN ("CREATE TABLE IF NOT EXISTS membership (\n" + " channel_id INT NOT NULL REFERENCES channels(id),\n" + " slave_id INT NOT NULL REFERENCES slaves(id),\n" + " did_join INT NOT NULL,\n" + " announced_at BIGINT UNSIGNED NOT NULL,\n" + " effective_since BIGINT UNSIGNED NOT NULL,\n" + " group_generation BIGINT UNSIGNED NOT NULL\n" + ");"); /*** FIX because IF NOT EXISTS doesn't work ***/ GNUNET_MYSQL_statement_run (plugin->mc, @@ -319,39 +326,37 @@ database_setup (struct Plugin *plugin) "ON membership (channel_id, slave_id);"); /** @todo messages table: add method_name column */ - GNUNET_MYSQL_statement_run (plugin->mc, - "CREATE TABLE IF NOT EXISTS messages (\n" - " channel_id INT NOT NULL REFERENCES channels(id),\n" - " hop_counter BIGINT UNSIGNED NOT NULL,\n" - " signature BLOB,\n" - " purpose BLOB,\n" - " fragment_id BIGINT UNSIGNED NOT NULL,\n" - " fragment_offset BIGINT UNSIGNED NOT NULL,\n" + STMT_RUN ("CREATE TABLE IF NOT EXISTS messages (\n" + " channel_id INT NOT NULL REFERENCES channels(id),\n" + " hop_counter BIGINT UNSIGNED NOT NULL,\n" + " signature BLOB,\n" + " purpose BLOB,\n" + " fragment_id BIGINT UNSIGNED NOT NULL,\n" + " fragment_offset BIGINT UNSIGNED NOT NULL,\n" " message_id BIGINT UNSIGNED NOT NULL,\n" - " group_generation BIGINT UNSIGNED NOT NULL,\n" - " multicast_flags BIGINT UNSIGNED NOT NULL,\n" - " psycstore_flags BIGINT UNSIGNED NOT NULL,\n" - " data BLOB,\n" - " PRIMARY KEY (channel_id, fragment_id),\n" - " UNIQUE KEY(channel_id, message_id, fragment_offset)\n" - ");"); - - GNUNET_MYSQL_statement_run (plugin->mc, - "CREATE TABLE IF NOT EXISTS state (\n" - " channel_id INT NOT NULL REFERENCES channels(id),\n" - " name TEXT NOT NULL,\n" - " value_current BLOB,\n" - " value_signed BLOB,\n" - " PRIMARY KEY (channel_id, name(5))\n" - ");"); - - GNUNET_MYSQL_statement_run (plugin->mc, - "CREATE TABLE IF NOT EXISTS state_sync (\n" - " channel_id INT NOT NULL REFERENCES channels(id),\n" - " name TEXT NOT NULL,\n" - " value BLOB,\n" - " PRIMARY KEY (channel_id, name(5))\n" - ");"); + " group_generation BIGINT UNSIGNED NOT NULL,\n" + " multicast_flags BIGINT UNSIGNED NOT NULL,\n" + " psycstore_flags BIGINT UNSIGNED NOT NULL,\n" + " data BLOB,\n" + " PRIMARY KEY (channel_id, fragment_id),\n" + " UNIQUE KEY(channel_id, message_id, fragment_offset)\n" + ");"); + + STMT_RUN ("CREATE TABLE IF NOT EXISTS state (\n" + " channel_id INT NOT NULL REFERENCES channels(id),\n" + " name TEXT NOT NULL,\n" + " value_current BLOB,\n" + " value_signed BLOB,\n" + " PRIMARY KEY (channel_id, name(5))\n" + ");"); + + STMT_RUN ("CREATE TABLE IF NOT EXISTS state_sync (\n" + " channel_id INT NOT NULL REFERENCES channels(id),\n" + " name TEXT NOT NULL,\n" + " value BLOB,\n" + " PRIMARY KEY (channel_id, name(5))\n" + ");"); +#undef STMT_RUN /* Prepare statements */ mysql_prepare (plugin->mc, diff --git a/src/psycstore/test_plugin_psycstore.c b/src/psycstore/test_plugin_psycstore.c index c1a456e60..d24405cc2 100644 --- a/src/psycstore/test_plugin_psycstore.c +++ b/src/psycstore/test_plugin_psycstore.c @@ -173,6 +173,7 @@ run (void *cls, char *const *args, const char *cfgfile, "%s", "Failed to initialize PSYCstore. " "Database likely not setup, skipping test.\n"); + ok = 77; return; } @@ -511,7 +512,8 @@ main (int argc, char *argv[]) GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1, xargv, "test-plugin-psycstore", "nohelp", options, &run, NULL); - if (ok != 0) + if ( (0 != ok) && + (77 != ok) ) FPRINTF (stderr, "Missed some testcases: %d\n", ok); #if ! DEBUG_PSYCSTORE