#At file:///home/cbell/source/bzr/mysql-wl-5710/ based on revid:chuck.bell@stripped
3423 Chuck Bell 2011-06-30
BUG#12664302 : Enable and disable plugins (mysql_plugin)
This patch changes the plugin configuration file format to make it
easier to add new plugins and remove complexity. It also adds more
information when plugin configuration file reads fail.
removed:
mysql-test/include/daemon_example.ini
added:
mysql-test/include/daemon_example_bad_soname.ini
modified:
client/mysql_plugin.c
mysql-test/include/daemon_example_bad_format.ini
mysql-test/r/mysql_plugin.result
mysql-test/t/mysql_plugin.test
plugin/daemon_example/daemon_example.ini
=== modified file 'client/mysql_plugin.c'
--- a/client/mysql_plugin.c 2011-06-14 20:00:51 +0000
+++ b/client/mysql_plugin.c 2011-06-30 12:12:58 +0000
@@ -41,9 +41,9 @@ static char bootstrap[FN_REFLEN];
/* plugin struct */
struct st_plugin
{
- const char *name; /* plugin name */
- const char *so_name; /* plugin so (library) name */
- const char *symbols[16]; /* symbols to load */
+ const char *name; /* plugin name */
+ const char *so_name; /* plugin so (library) name */
+ const char *components[16]; /* components to load */
} plugin_data;
@@ -492,123 +492,96 @@ static int search_paths(const char *base
/**
- Read a plugin data element
-
- This method takes as input a line from the plugin.ini file and splits it
- into the st_plugin structure.
-
- @retval int error = 1, success = 0
-*/
-
-static int read_plugin_data(char *line)
-{
- const char delimiters[]= " ,";
- char *token, *cp;
- int i= 0;
- int error= 0;
-
- cp= my_strdup(line, MYF(MY_FAE));
- token= strtok (cp, delimiters);
- if (token != NULL)
- {
- /* read name */
- plugin_data.name= my_strdup(token, MYF(MY_WME));
- /* read so_name */
- token = strtok(NULL, delimiters);
- if (token == NULL)
- {
- return 1;
- }
- plugin_data.so_name= my_strdup(token, MYF(MY_WME));
- if (plugin_data.so_name == NULL)
- {
- error= 1;
- goto exit;
- }
- /* Add proper file extension for soname */
- strcat((char *)plugin_data.so_name, FN_SOEXT);
- /* read symbols */
- while (token != NULL)
- {
- token= strtok (NULL, delimiters);
- if ((token != NULL) && (token[0] != '\n'))
- {
- plugin_data.symbols[i]= my_strdup(token, MYF(MY_WME));
- i++;
- }
- else
- {
- plugin_data.symbols[i]= NULL;
- }
- }
- }
-
-exit:
- if (error)
- {
- fprintf(stderr, "ERROR: Format incorrect for plugin config file.\n");
- }
-
- return error;
-}
-
-
-/**
Read the plugin ini file.
This function attempts to read the plugin config file from the plugin_dir
- path. If the file is not found, an error is generated.
+ path saving the data in the the st_plugin structure. If the file is not
+ found or the file cannot be read, an error is generated.
@retval int error = 1, success = 0
*/
-static int load_plugin_data(char *plugin_name)
+static int load_plugin_data(char *plugin_name, char *config_file)
{
FILE *file_ptr;
char path[FN_REFLEN];
char line[1024];
- int i= 0;
+ char *reason= 0;
+ char *res;
+ int i= -1;
if (opt_plugin_ini == 0)
{
- fn_format(path, plugin_name, opt_plugin_dir, "", MYF(0));
+ fn_format(path, config_file, opt_plugin_dir, "", MYF(0));
opt_plugin_ini= my_strdup(path, MYF(MY_FAE));
}
if (!file_exists(opt_plugin_ini))
{
+ reason= "File does not exist.";
goto error;
}
file_ptr= fopen(opt_plugin_ini, "r");
if (file_ptr == NULL)
{
+ reason= "Cannot open file.";
goto error;
}
- i = 0;
- while (1)
+
+ /* save name */
+ plugin_data.name= my_strdup(plugin_name, MYF(MY_WME));
+
+ /* Read plugin components */
+ while (i < 16)
{
- char *res;
res= fgets(line, sizeof(line), file_ptr);
+ /* strip /n */
+ if (line[strlen(line)-1] == '\n')
+ {
+ line[strlen(line)-1]= '\0';
+ }
if (res == NULL)
{
+ if (i < 1)
+ {
+ reason= "Bad format in plugin configuration file.";
+ fclose(file_ptr);
+ goto error;
+ }
break;
}
- if (line[0] == '#') // skip comment lines
+ if ((line[0] == '#') || (line[0] == '\n')) // skip comment and blank lines
{
continue;
}
- if (read_plugin_data(line))
+ if (i == -1) // if first pass, read this line as so_name
+ {
+ /* save so_name */
+ plugin_data.so_name= my_strdup(line, MYF(MY_WME));
+ /* Add proper file extension for soname */
+ strcat((char *)plugin_data.so_name, FN_SOEXT);
+ i++;
+ }
+ else
{
- fclose(file_ptr);
- goto error;
+ if (strlen(line) > 0)
+ {
+ plugin_data.components[i]= my_strdup(line, MYF(MY_WME));
+ i++;
+ }
+ else
+ {
+ plugin_data.components[i]= NULL;
+ }
}
}
+
fclose(file_ptr);
return 0;
error:
- fprintf(stderr, "ERROR: Cannot read plugin config file %s.\n",
- plugin_name);
+ fprintf(stderr, "ERROR: Cannot read plugin config file %s. %s\n",
+ plugin_name, reason);
return 1;
}
@@ -706,7 +679,7 @@ static int check_options(int argc, char
/* If a plugin was specified, read the config file. */
else if (strlen(plugin_name) > 0)
{
- if (load_plugin_data(config_file))
+ if (load_plugin_data(plugin_name, config_file))
{
return 1;
}
@@ -954,10 +927,10 @@ static int build_bootstrap_file(char *op
{
int i= 0;
fprintf(file, "INSERT IGNORE INTO mysql.plugin VALUES ");
- for (i= 0; i < (int)array_elements(plugin_data.symbols); i++)
+ for (i= 0; i < (int)array_elements(plugin_data.components); i++)
{
/* stop when we read the end of the symbol list - marked with NULL */
- if (plugin_data.symbols[i] == NULL)
+ if (plugin_data.components[i] == NULL)
{
break;
}
@@ -966,7 +939,7 @@ static int build_bootstrap_file(char *op
fprintf(file, ", ");
}
fprintf(file, "('%s','%s')",
- plugin_data.symbols[i], plugin_data.so_name);
+ plugin_data.components[i], plugin_data.so_name);
}
fprintf(file, ";\n");
if (opt_verbose)
=== removed file 'mysql-test/include/daemon_example.ini'
--- a/mysql-test/include/daemon_example.ini 2011-06-14 20:00:51 +0000
+++ b/mysql-test/include/daemon_example.ini 1970-01-01 00:00:00 +0000
@@ -1,8 +0,0 @@
-#
-# Plugin initialization file. Format using comma-separated values:
-# name, libname, symbol, [symbol, ]
-# Note: trailing comma is required.
-#
-# File is used by mysql_plugin.test for testing missing library error.
-#
-daemon_example, libdaemon_example, daemon_example,
=== modified file 'mysql-test/include/daemon_example_bad_format.ini'
--- a/mysql-test/include/daemon_example_bad_format.ini 2011-06-14 20:00:51 +0000
+++ b/mysql-test/include/daemon_example_bad_format.ini 2011-06-30 12:12:58 +0000
@@ -1,8 +1,8 @@
#
-# Plugin initialization file. Format using comma-separated values:
-# name, libname, symbol, [symbol, ]
-# Note: trailing comma is required.
+# Plugin configuration file. Place the following on a separate line:
#
-# File is used by mysql_plugin.test for testing bad library name.
+# library binary file name (without .so or .dll)
+# component_name
+# [component_name] - additional components in plugin
#
-daemon_BADNAME, libdaemon_example, daemon_example,
+libdaemon_example
=== added file 'mysql-test/include/daemon_example_bad_soname.ini'
--- a/mysql-test/include/daemon_example_bad_soname.ini 1970-01-01 00:00:00 +0000
+++ b/mysql-test/include/daemon_example_bad_soname.ini 2011-06-30 12:12:58 +0000
@@ -0,0 +1,9 @@
+#
+# Plugin configuration file. Place the following on a separate line:
+#
+# library binary file name (without .so or .dll)
+# component_name
+# [component_name] - additional components in plugin
+#
+libdaemon_BADNAME
+daemon_BADNAME
=== modified file 'mysql-test/r/mysql_plugin.result'
--- a/mysql-test/r/mysql_plugin.result 2011-06-14 20:00:51 +0000
+++ b/mysql-test/r/mysql_plugin.result 2011-06-30 12:12:58 +0000
@@ -23,11 +23,11 @@ name dl
#
# Attempt to load non-existant plugin
#
-ERROR: Cannot read plugin config file NOT_THERE_AT_ALL.ini.
+ERROR: Cannot read plugin config file NOT_THERE_AT_ALL. File does not exist.
#
# Attempt to use non-existant plugin.ini file
#
-ERROR: Cannot read plugin config file daemon_example.ini.
+ERROR: Cannot read plugin config file daemon_example. File does not exist.
#
# Attempt to omit the plugin
#
@@ -47,7 +47,7 @@ ERROR: Cannot access basedir at '/basedi
#
# Attempt to use bad paths - plugin_dir
#
-ERROR: Cannot read plugin config file daemon_example.ini.
+ERROR: Cannot read plugin config file daemon_example. File does not exist.
#
# Missing library
#
@@ -55,7 +55,7 @@ ERROR: The plugin library is missing or
#
# Bad format for config file
#
-ERROR: plugin name requested does not match config file data.
+ERROR: Cannot read plugin config file daemon_example. Bad format in plugin configuration file.
#
# Missing base_dir option
#
=== modified file 'mysql-test/t/mysql_plugin.test'
--- a/mysql-test/t/mysql_plugin.test 2011-06-14 20:00:51 +0000
+++ b/mysql-test/t/mysql_plugin.test 2011-06-30 12:12:58 +0000
@@ -149,7 +149,7 @@ let $MYSQLD_BOOTSTRAP_CMD= $MYSQL_PLUGIN
--echo #
--echo # Missing library
--echo #
-let $MYSQLD_BOOTSTRAP_CMD= $MYSQL_PLUGIN -n --datadir=$MYSQLD_DATADIR --basedir=$MYSQLD_BASEDIR/sql --plugin-dir=$MYSQL_TEST_DIR/include/;
+let $MYSQLD_BOOTSTRAP_CMD= $MYSQL_PLUGIN -n --datadir=$MYSQLD_DATADIR --basedir=$MYSQLD_BASEDIR/sql --plugin-dir=$DAEMONEXAMPLE_DIR --plugin-ini=$MYSQL_TEST_DIR/include/daemon_example_bad_soname.ini;
--error 1,2,256
--exec $MYSQLD_BOOTSTRAP_CMD DISABLE daemon_example 2>&1
=== modified file 'plugin/daemon_example/daemon_example.ini'
--- a/plugin/daemon_example/daemon_example.ini 2011-06-14 20:00:51 +0000
+++ b/plugin/daemon_example/daemon_example.ini 2011-06-30 12:12:58 +0000
@@ -1,6 +1,9 @@
#
-# Plugin initialization file. Format using comma-separated values:
-# name, libname, symbol, [symbol, ]
-# Note: trailing comma is required.
+# Plugin configuration file. Place the following on a separate line:
#
-daemon_example, libdaemon_example, daemon_example,
+# library binary file name (without .so or .dll)
+# component_name
+# [component_name] - additional components in plugin
+#
+libdaemon_example
+daemon_example
Attachment: [text/bzr-bundle] bzr/chuck.bell@oracle.com-20110630121258-auxcaj5ind2hmam3.bundle
| Thread |
|---|
| • bzr commit into mysql-5.5 branch (chuck.bell:3423) Bug#12664302 | Chuck Bell | 4 Jul |