summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexey Kopytov <Alexey.Kopytov@sun.com>2009-03-16 13:37:13 +0300
committerAlexey Kopytov <Alexey.Kopytov@sun.com>2009-03-16 13:37:13 +0300
commitb00996e85f77bee984b409e7b48f47d716b5d709 (patch)
treed8831432063fa4577460a57a59e8f5bcfeabbff7
parent0a050535936a7402bb17cda642505935f131d564 (diff)
parent752cbab9a4c553871cab9e5fdb8968019617cc28 (diff)
downloadmariadb-git-b00996e85f77bee984b409e7b48f47d716b5d709.tar.gz
Manual merge of patch for bug #40552 into the team tree.
Replaced a call to load_defaults() in sql_plugin.cc with its thread-safe version.
-rw-r--r--include/my_sys.h7
-rw-r--r--mysys/default.c65
-rw-r--r--server-tools/instance-manager/instance_map.cc3
-rw-r--r--server-tools/instance-manager/options.cc4
-rw-r--r--server-tools/instance-manager/options.h3
-rw-r--r--sql-common/client.c2
-rw-r--r--sql/sql_plugin.cc2
7 files changed, 66 insertions, 20 deletions
diff --git a/include/my_sys.h b/include/my_sys.h
index 8fda6178f6b..01804cd089f 100644
--- a/include/my_sys.h
+++ b/include/my_sys.h
@@ -843,14 +843,17 @@ extern void *memdup_root(MEM_ROOT *root,const void *str, size_t len);
extern int get_defaults_options(int argc, char **argv,
char **defaults, char **extra_defaults,
char **group_suffix);
+extern int my_load_defaults(const char *conf_file, const char **groups,
+ int *argc, char ***argv, const char ***);
extern int load_defaults(const char *conf_file, const char **groups,
- int *argc, char ***argv);
+ int *argc, char ***argv);
extern int modify_defaults_file(const char *file_location, const char *option,
const char *option_value,
const char *section_name, int remove_option);
extern int my_search_option_files(const char *conf_file, int *argc,
char ***argv, uint *args_used,
- Process_option_func func, void *func_ctx);
+ Process_option_func func, void *func_ctx,
+ const char **default_directories);
extern void free_defaults(char **argv);
extern void my_print_default_files(const char *conf_file);
extern void print_defaults(const char *conf_file, const char **groups);
diff --git a/mysys/default.c b/mysys/default.c
index c7e1e513e1e..a6995dbbd24 100644
--- a/mysys/default.c
+++ b/mysys/default.c
@@ -152,7 +152,7 @@ static char *remove_end_comment(char *ptr);
int my_search_option_files(const char *conf_file, int *argc, char ***argv,
uint *args_used, Process_option_func func,
- void *func_ctx)
+ void *func_ctx, const char **default_directories)
{
const char **dirs, *forced_default_file, *forced_extra_defaults;
int error= 0;
@@ -359,18 +359,46 @@ int get_defaults_options(int argc, char **argv,
return org_argc - argc;
}
+/*
+ Wrapper around my_load_defaults() for interface compatibility.
+
+ SYNOPSIS
+ load_defaults()
+ conf_file Basename for configuration file to search for.
+ If this is a path, then only this file is read.
+ groups Which [group] entrys to read.
+ Points to an null terminated array of pointers
+ argc Pointer to argc of original program
+ argv Pointer to argv of original program
+
+ NOTES
+
+ This function is NOT thread-safe as it uses a global pointer internally.
+ See also notes for my_load_defaults().
+
+ RETURN
+ 0 ok
+ 1 The given conf_file didn't exists
+*/
+int load_defaults(const char *conf_file, const char **groups,
+ int *argc, char ***argv)
+{
+ return my_load_defaults(conf_file, groups, argc, argv, &default_directories);
+}
/*
Read options from configurations files
SYNOPSIS
- load_defaults()
+ my_load_defaults()
conf_file Basename for configuration file to search for.
If this is a path, then only this file is read.
groups Which [group] entrys to read.
Points to an null terminated array of pointers
argc Pointer to argc of original program
argv Pointer to argv of original program
+ default_directories Pointer to a location where a pointer to the list
+ of default directories will be stored
IMPLEMENTATION
@@ -386,13 +414,18 @@ int get_defaults_options(int argc, char **argv,
that was put in *argv
RETURN
- 0 ok
- 1 The given conf_file didn't exists
+ - If successful, 0 is returned. If 'default_directories' is not NULL,
+ a pointer to the array of default directory paths is stored to a location
+ it points to. That stored value must be passed to my_search_option_files()
+ later.
+
+ - 1 is returned if the given conf_file didn't exist. In this case, the
+ value pointed to by default_directories is undefined.
*/
-int load_defaults(const char *conf_file, const char **groups,
- int *argc, char ***argv)
+int my_load_defaults(const char *conf_file, const char **groups,
+ int *argc, char ***argv, const char ***default_directories)
{
DYNAMIC_ARRAY args;
TYPELIB group;
@@ -402,10 +435,11 @@ int load_defaults(const char *conf_file, const char **groups,
MEM_ROOT alloc;
char *ptr,**res;
struct handle_option_ctx ctx;
+ const char **dirs;
DBUG_ENTER("load_defaults");
init_alloc_root(&alloc,512,0);
- if ((default_directories= init_default_directories(&alloc)) == NULL)
+ if ((dirs= init_default_directories(&alloc)) == NULL)
goto err;
/*
Check if the user doesn't want any default option processing
@@ -426,6 +460,8 @@ int load_defaults(const char *conf_file, const char **groups,
(*argc)--;
*argv=res;
*(MEM_ROOT*) ptr= alloc; /* Save alloc root for free */
+ if (default_directories)
+ *default_directories= dirs;
DBUG_RETURN(0);
}
@@ -444,7 +480,8 @@ int load_defaults(const char *conf_file, const char **groups,
ctx.group= &group;
error= my_search_option_files(conf_file, argc, argv, &args_used,
- handle_default_option, (void *) &ctx);
+ handle_default_option, (void *) &ctx,
+ dirs);
/*
Here error contains <> 0 only if we have a fully specified conf_file
or a forced default file
@@ -490,6 +527,10 @@ int load_defaults(const char *conf_file, const char **groups,
puts("");
exit(0);
}
+
+ if (error == 0 && default_directories)
+ *default_directories= dirs;
+
DBUG_RETURN(error);
err:
@@ -895,15 +936,11 @@ void my_print_default_files(const char *conf_file)
fputs(conf_file,stdout);
else
{
- /*
- If default_directories is already initialized, use it. Otherwise,
- use a private MEM_ROOT.
- */
- const char **dirs = default_directories;
+ const char **dirs;
MEM_ROOT alloc;
init_alloc_root(&alloc,512,0);
- if (!dirs && (dirs= init_default_directories(&alloc)) == NULL)
+ if ((dirs= init_default_directories(&alloc)) == NULL)
{
fputs("Internal error initializing default directories list", stdout);
}
diff --git a/server-tools/instance-manager/instance_map.cc b/server-tools/instance-manager/instance_map.cc
index d7328d51cfe..b137370b50a 100644
--- a/server-tools/instance-manager/instance_map.cc
+++ b/server-tools/instance-manager/instance_map.cc
@@ -536,7 +536,8 @@ int Instance_map::load()
*/
if (my_search_option_files(Options::Main::config_file, &argc,
(char ***) &argv, &args_used,
- process_option, (void*) this))
+ process_option, (void*) this,
+ Options::default_directories))
log_info("Falling back to compiled-in defaults.");
return complete_initialization();
diff --git a/server-tools/instance-manager/options.cc b/server-tools/instance-manager/options.cc
index 7eba3187dd9..6f084e7c63e 100644
--- a/server-tools/instance-manager/options.cc
+++ b/server-tools/instance-manager/options.cc
@@ -86,6 +86,7 @@ const char *Options::Main::bind_address= NULL; /* No default value */
uint Options::Main::monitoring_interval= DEFAULT_MONITORING_INTERVAL;
uint Options::Main::port_number= DEFAULT_PORT;
my_bool Options::Main::mysqld_safe_compatible= FALSE;
+const char **Options::default_directories= NULL;
/* Options::User_management */
@@ -439,7 +440,8 @@ int Options::load(int argc, char **argv)
log_info("Loading config file '%s'...",
(const char *) Main::config_file);
- load_defaults(Main::config_file, default_groups, &argc, &saved_argv);
+ my_load_defaults(Main::config_file, default_groups, &argc,
+ &saved_argv, &default_directories);
if ((handle_options(&argc, &saved_argv, my_long_options, get_one_option)))
return ERR_INVALID_USAGE;
diff --git a/server-tools/instance-manager/options.h b/server-tools/instance-manager/options.h
index 0202ca271c9..5d4df51faae 100644
--- a/server-tools/instance-manager/options.h
+++ b/server-tools/instance-manager/options.h
@@ -91,6 +91,9 @@ struct Options
#endif
public:
+ /* Array of paths to be passed to my_search_option_files() later */
+ static const char **default_directories;
+
static int load(int argc, char **argv);
static void cleanup();
diff --git a/sql-common/client.c b/sql-common/client.c
index 63c746a3f5a..91a47b6a6f8 100644
--- a/sql-common/client.c
+++ b/sql-common/client.c
@@ -1021,7 +1021,7 @@ void mysql_read_default_options(struct st_mysql_options *options,
argc=1; argv=argv_buff; argv_buff[0]= (char*) "client";
groups[0]= (char*) "client"; groups[1]= (char*) group; groups[2]=0;
- load_defaults(filename, groups, &argc, &argv);
+ my_load_defaults(filename, groups, &argc, &argv, NULL);
if (argc != 1) /* If some default option */
{
char **option=argv;
diff --git a/sql/sql_plugin.cc b/sql/sql_plugin.cc
index 223ba6ef42e..1465b6d2d30 100644
--- a/sql/sql_plugin.cc
+++ b/sql/sql_plugin.cc
@@ -1652,7 +1652,7 @@ bool mysql_install_plugin(THD *thd, const LEX_STRING *name, const LEX_STRING *dl
pthread_mutex_lock(&LOCK_plugin);
rw_wrlock(&LOCK_system_variables_hash);
- load_defaults(MYSQL_CONFIG_NAME, load_default_groups, &argc, &argv);
+ my_load_defaults(MYSQL_CONFIG_NAME, load_default_groups, &argc, &argv, NULL);
error= plugin_add(thd->mem_root, name, dl, &argc, argv, REPORT_TO_USER);
if (argv)
free_defaults(argv);