Commit dbc0937d authored by petr@mysql.com's avatar petr@mysql.com

made IM to work with --defaults-file smoothly

parent 7dbe6f3b
...@@ -531,7 +531,7 @@ typedef uint32 ha_checksum; ...@@ -531,7 +531,7 @@ typedef uint32 ha_checksum;
/* Define the type of function to be passed to process_default_option_files */ /* Define the type of function to be passed to process_default_option_files */
typedef int (*Process_option_func)(void *ctx, const char *group_name, typedef int (*Process_option_func)(void *ctx, const char *group_name,
const char *option); const char *option);
#include <my_alloc.h> #include <my_alloc.h>
...@@ -776,9 +776,9 @@ extern void get_defaults_files(int argc, char **argv, ...@@ -776,9 +776,9 @@ extern void get_defaults_files(int argc, char **argv,
char **defaults, char **extra_defaults); char **defaults, char **extra_defaults);
extern int load_defaults(const char *conf_file, const char **groups, extern int load_defaults(const char *conf_file, const char **groups,
int *argc, char ***argv); int *argc, char ***argv);
extern int process_default_option_files(const char *conf_file, extern int my_search_option_files(const char *conf_file, int *argc,
Process_option_func func, char ***argv, uint *args_used,
void *func_ctx); Process_option_func func, void *func_ctx);
extern void free_defaults(char **argv); extern void free_defaults(char **argv);
extern void print_defaults(const char *conf_file, const char **groups); extern void print_defaults(const char *conf_file, const char **groups);
extern my_bool my_compress(byte *, ulong *, ulong *); extern my_bool my_compress(byte *, ulong *, ulong *);
......
...@@ -83,7 +83,7 @@ static char *remove_end_comment(char *ptr); ...@@ -83,7 +83,7 @@ static char *remove_end_comment(char *ptr);
Process config files in default directories. Process config files in default directories.
SYNOPSIS SYNOPSIS
search_files() my_search_option_files()
conf_file Basename for configuration file to search for. conf_file Basename for configuration file to search for.
If this is a path, then only this file is read. If this is a path, then only this file is read.
argc Pointer to argc of original program argc Pointer to argc of original program
...@@ -103,13 +103,13 @@ static char *remove_end_comment(char *ptr); ...@@ -103,13 +103,13 @@ static char *remove_end_comment(char *ptr);
1 given cinf_file doesn't exist 1 given cinf_file doesn't exist
*/ */
static int search_files(const char *conf_file, int *argc, char ***argv, int my_search_option_files(const char *conf_file, int *argc, char ***argv,
uint *args_used, Process_option_func func, uint *args_used, Process_option_func func,
void *func_ctx) void *func_ctx)
{ {
const char **dirs, *forced_default_file; const char **dirs, *forced_default_file;
int error= 0; int error= 0;
DBUG_ENTER("search_files"); DBUG_ENTER("my_search_option_files");
/* Check if we want to force the use a specific default file */ /* Check if we want to force the use a specific default file */
get_defaults_files(*argc, *argv, get_defaults_files(*argc, *argv,
...@@ -180,40 +180,6 @@ static int search_files(const char *conf_file, int *argc, char ***argv, ...@@ -180,40 +180,6 @@ static int search_files(const char *conf_file, int *argc, char ***argv,
} }
/*
Simplified version of search_files (no argv, argc to process).
SYNOPSIS
process_default_option_files()
conf_file Basename for configuration file to search for.
If this is a path, then only this file is read.
func Pointer to the function to process options
func_ctx It's context. Usually it is the structure to
store additional options.
DESCRIPTION
Often we want only to get options from default config files. In this case we
don't want to provide any argc and argv parameters. This function is a
simplified variant of search_files which allows us to forget about
argc, argv.
RETURN
0 ok
1 given cinf_file doesn't exist
*/
int process_default_option_files(const char *conf_file,
Process_option_func func, void *func_ctx)
{
int argc= 1;
/* this is a dummy variable for search_files() */
uint args_used;
return search_files(conf_file, &argc, NULL, &args_used, func, func_ctx);
}
/* /*
The option handler for load_defaults. The option handler for load_defaults.
...@@ -363,7 +329,7 @@ int load_defaults(const char *conf_file, const char **groups, ...@@ -363,7 +329,7 @@ int load_defaults(const char *conf_file, const char **groups,
ctx.args= &args; ctx.args= &args;
ctx.group= &group; ctx.group= &group;
error= search_files(conf_file, argc, argv, &args_used, error= my_search_option_files(conf_file, argc, argv, &args_used,
handle_default_option, (void *) &ctx); handle_default_option, (void *) &ctx);
/* /*
Here error contains <> 0 only if we have a fully specified conf_file Here error contains <> 0 only if we have a fully specified conf_file
......
...@@ -297,8 +297,9 @@ int Instance::init(const char *name_arg) ...@@ -297,8 +297,9 @@ int Instance::init(const char *name_arg)
int Instance::complete_initialization(Instance_map *instance_map_arg, int Instance::complete_initialization(Instance_map *instance_map_arg,
const char *mysqld_path) const char *mysqld_path,
int only_instance)
{ {
instance_map= instance_map_arg; instance_map= instance_map_arg;
return options.complete_initialization(mysqld_path); return options.complete_initialization(mysqld_path, only_instance);
} }
...@@ -35,7 +35,7 @@ class Instance ...@@ -35,7 +35,7 @@ class Instance
~Instance(); ~Instance();
int init(const char *name); int init(const char *name);
int complete_initialization(Instance_map *instance_map_arg, int complete_initialization(Instance_map *instance_map_arg,
const char *mysqld_path); const char *mysqld_path, int only_instance= 0);
bool is_running(); bool is_running();
int start(); int start();
......
...@@ -110,10 +110,10 @@ static int process_option(void *ctx, const char *group, const char *option) ...@@ -110,10 +110,10 @@ static int process_option(void *ctx, const char *group, const char *option)
C_MODE_END C_MODE_END
Instance_map::Instance_map(const char *default_mysqld_path_arg) Instance_map::Instance_map(const char *default_mysqld_path_arg,
const char *first_option_arg):
mysqld_path(default_mysqld_path_arg), first_option(first_option_arg)
{ {
mysqld_path= default_mysqld_path_arg;
pthread_mutex_init(&LOCK_instance_map, 0); pthread_mutex_init(&LOCK_instance_map, 0);
} }
...@@ -193,9 +193,10 @@ int Instance_map::complete_initialization() ...@@ -193,9 +193,10 @@ int Instance_map::complete_initialization()
/* /*
After an instance have been added to the instance_map, After an instance have been added to the instance_map,
hash_free should handle it's deletion. hash_free should handle it's deletion => goto err, not
err_instance.
*/ */
if (instance->complete_initialization(this, mysqld_path)) if (instance->complete_initialization(this, mysqld_path, 1))
goto err; goto err;
} }
else else
...@@ -220,7 +221,25 @@ int Instance_map::complete_initialization() ...@@ -220,7 +221,25 @@ int Instance_map::complete_initialization()
int Instance_map::load() int Instance_map::load()
{ {
if (process_default_option_files("my", process_option, (void *) this) || int argc= 1;
/* this is a dummy variable for search_option_files() */
uint args_used= 0;
const char *argv_options[3];
char **argv= (char **) &argv_options;
/* the name of the program may be orbitrary here in fact */
argv_options[0]= "mysqlmanager";
if (first_option != NULL)
{
argc= 2;
argv_options[1]= first_option;
argv_options[2]= '\0';
}
else
argv_options[1]= '\0';
if (my_search_option_files("my", &argc, (char ***) &argv, &args_used,
process_option, (void *) this) ||
complete_initialization()) complete_initialization())
return 1; return 1;
......
...@@ -64,7 +64,8 @@ class Instance_map ...@@ -64,7 +64,8 @@ class Instance_map
int unlock(); int unlock();
int init(); int init();
Instance_map(const char *default_mysqld_path_arg); Instance_map(const char *default_mysqld_path_arg,
const char *first_option_arg);
~Instance_map(); ~Instance_map();
/* loads options from config files */ /* loads options from config files */
...@@ -79,6 +80,7 @@ class Instance_map ...@@ -79,6 +80,7 @@ class Instance_map
Guardian_thread *guardian; Guardian_thread *guardian;
private: private:
const char *first_option;
enum { START_HASH_SIZE = 16 }; enum { START_HASH_SIZE = 16 };
pthread_mutex_t LOCK_instance_map; pthread_mutex_t LOCK_instance_map;
HASH hash; HASH hash;
......
...@@ -123,7 +123,8 @@ pid_t Instance_options::get_pid() ...@@ -123,7 +123,8 @@ pid_t Instance_options::get_pid()
} }
int Instance_options::complete_initialization(const char *default_path) int Instance_options::complete_initialization(const char *default_path,
int only_instance)
{ {
const char *tmp; const char *tmp;
...@@ -140,11 +141,23 @@ int Instance_options::complete_initialization(const char *default_path) ...@@ -140,11 +141,23 @@ int Instance_options::complete_initialization(const char *default_path)
{ {
char pidfilename[MAX_PATH_LEN]; char pidfilename[MAX_PATH_LEN];
char hostname[MAX_PATH_LEN]; char hostname[MAX_PATH_LEN];
/*
If we created only one istance [mysqld], because no config. files were
found, we would like to model mysqld pid file values.
*/
if (!gethostname(hostname, sizeof(hostname) - 1)) if (!gethostname(hostname, sizeof(hostname) - 1))
strxnmov(pidfilename, MAX_PATH_LEN - 1, "--pid-file=", hostname, "-", (only_instance == 0) ?
instance_name, ".pid", NullS); strxnmov(pidfilename, MAX_PATH_LEN - 1, "--pid-file=", instance_name, "-",
hostname, ".pid", NullS):
strxnmov(pidfilename, MAX_PATH_LEN - 1, "--pid-file=", hostname,
".pid", NullS);
else else
(only_instance == 0) ?
strxnmov(pidfilename, MAX_PATH_LEN - 1, "--pid-file=", instance_name, strxnmov(pidfilename, MAX_PATH_LEN - 1, "--pid-file=", instance_name,
".pid", NullS):
strxnmov(pidfilename, MAX_PATH_LEN - 1, "--pid-file=", "mysql",
".pid", NullS); ".pid", NullS);
add_option(pidfilename); add_option(pidfilename);
......
...@@ -43,7 +43,7 @@ class Instance_options ...@@ -43,7 +43,7 @@ class Instance_options
{} {}
~Instance_options(); ~Instance_options();
/* fills in argv */ /* fills in argv */
int complete_initialization(const char *default_path); int complete_initialization(const char *default_path, int only_instance);
int add_option(const char* option); int add_option(const char* option);
int init(const char *instance_name_arg); int init(const char *instance_name_arg);
......
...@@ -67,7 +67,7 @@ void manager(const Options &options) ...@@ -67,7 +67,7 @@ void manager(const Options &options)
*/ */
User_map user_map; User_map user_map;
Instance_map instance_map(options.default_mysqld_path); Instance_map instance_map(options.default_mysqld_path, options.first_option);
Guardian_thread guardian_thread(thread_registry, Guardian_thread guardian_thread(thread_registry,
&instance_map, &instance_map,
options.monitoring_interval); options.monitoring_interval);
......
...@@ -37,6 +37,7 @@ const char *Options::pid_file_name= QUOTE(DEFAULT_PID_FILE_NAME); ...@@ -37,6 +37,7 @@ const char *Options::pid_file_name= QUOTE(DEFAULT_PID_FILE_NAME);
const char *Options::socket_file_name= QUOTE(DEFAULT_SOCKET_FILE_NAME); const char *Options::socket_file_name= QUOTE(DEFAULT_SOCKET_FILE_NAME);
const char *Options::password_file_name= QUOTE(DEFAULT_PASSWORD_FILE_NAME); const char *Options::password_file_name= QUOTE(DEFAULT_PASSWORD_FILE_NAME);
const char *Options::default_mysqld_path= QUOTE(DEFAULT_MYSQLD_PATH); const char *Options::default_mysqld_path= QUOTE(DEFAULT_MYSQLD_PATH);
const char *Options::first_option= 0; /* No default value */
const char *Options::bind_address= 0; /* No default value */ const char *Options::bind_address= 0; /* No default value */
const char *Options::user= 0; /* No default value */ const char *Options::user= 0; /* No default value */
uint Options::monitoring_interval= DEFAULT_MONITORING_INTERVAL; uint Options::monitoring_interval= DEFAULT_MONITORING_INTERVAL;
...@@ -210,10 +211,18 @@ C_MODE_END ...@@ -210,10 +211,18 @@ C_MODE_END
int Options::load(int argc, char **argv) int Options::load(int argc, char **argv)
{ {
int rc; int rc;
if (argc >= 2)
{
if (is_prefix(argv[1],"--defaults-file=") ||
is_prefix(argv[1],"--defaults-extra-file="))
Options::first_option= argv[1];
}
/* config-file options are prepended to command-line ones */ /* config-file options are prepended to command-line ones */
load_defaults("my", default_groups, &argc, &argv); load_defaults("my", default_groups, &argc, &argv);
if (rc= handle_options(&argc, &argv, my_long_options, get_one_option)) if ((rc= handle_options(&argc, &argv, my_long_options, get_one_option)) != 0)
return rc; return rc;
Options::saved_argv= argv; Options::saved_argv= argv;
return 0; return 0;
......
...@@ -35,6 +35,8 @@ struct Options ...@@ -35,6 +35,8 @@ struct Options
static const char *password_file_name; static const char *password_file_name;
static const char *default_mysqld_path; static const char *default_mysqld_path;
static const char *user; static const char *user;
/* the option which should be passed to process_default_option_files */
static const char *first_option;
static uint monitoring_interval; static uint monitoring_interval;
static uint port_number; static uint port_number;
static const char *bind_address; static const char *bind_address;
......
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
EXTRA_DIST = mysql.spec.sh \ EXTRA_DIST = mysql.spec.sh \
my-small.cnf.sh \ my-small.cnf.sh \
my.cnf \
my-medium.cnf.sh \ my-medium.cnf.sh \
my-large.cnf.sh \ my-large.cnf.sh \
my-huge.cnf.sh \ my-huge.cnf.sh \
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment