mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
some more cleanups and fixes
This commit is contained in:
@ -276,7 +276,7 @@ int Show_instance_options::do_command(struct st_net *net,
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (instance->options.nonguarded == NULL)
|
||||
if (instance->options.nonguarded != NULL)
|
||||
{
|
||||
position= 0;
|
||||
store_to_string(&send_buff, (char *) "nonguarded", &position);
|
||||
|
@ -296,8 +296,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)
|
||||
{
|
||||
instance_map= instance_map_arg;
|
||||
return 0;
|
||||
return options.complete_initialization(mysqld_path);
|
||||
}
|
||||
|
@ -34,7 +34,8 @@ public:
|
||||
|
||||
~Instance();
|
||||
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);
|
||||
|
||||
bool is_running();
|
||||
int start();
|
||||
|
@ -74,7 +74,7 @@ static void delete_instance(void *u)
|
||||
1 - error occured
|
||||
*/
|
||||
|
||||
static int process_option(void * ctx, const char *group, const char *option)
|
||||
static int process_option(void *ctx, const char *group, const char *option)
|
||||
{
|
||||
Instance_map *map= NULL;
|
||||
Instance *instance= NULL;
|
||||
@ -178,18 +178,41 @@ Instance_map::find(const char *name, uint name_len)
|
||||
}
|
||||
|
||||
|
||||
void Instance_map::complete_initialization()
|
||||
int Instance_map::complete_initialization()
|
||||
{
|
||||
Instance *instance;
|
||||
uint i= 0;
|
||||
|
||||
while (i < hash.records)
|
||||
if (hash.records == 0) /* no instances found */
|
||||
{
|
||||
instance= (Instance *) hash_element(&hash, i);
|
||||
instance->complete_initialization(this);
|
||||
instance->options.complete_initialization(mysqld_path);
|
||||
i++;
|
||||
if ((instance= new Instance) == 0)
|
||||
goto err;
|
||||
|
||||
if (instance->init("mysqld") || add_instance(instance))
|
||||
goto err_instance;
|
||||
|
||||
/*
|
||||
After an instance have been added to the instance_map,
|
||||
hash_free should handle it's deletion.
|
||||
*/
|
||||
if (instance->complete_initialization(this, mysqld_path))
|
||||
goto err;
|
||||
}
|
||||
else
|
||||
while (i < hash.records)
|
||||
{
|
||||
instance= (Instance *) hash_element(&hash, i);
|
||||
if (instance->complete_initialization(this, mysqld_path))
|
||||
goto err;
|
||||
i++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
err:
|
||||
return 1;
|
||||
err_instance:
|
||||
delete instance;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@ -197,13 +220,11 @@ void Instance_map::complete_initialization()
|
||||
|
||||
int Instance_map::load()
|
||||
{
|
||||
int error;
|
||||
if (process_default_option_files("my", process_option, (void *) this) ||
|
||||
complete_initialization())
|
||||
return 1;
|
||||
|
||||
error= process_default_option_files("my", process_option, (void *) this);
|
||||
|
||||
complete_initialization();
|
||||
|
||||
return error;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
@ -72,7 +72,7 @@ public:
|
||||
/* adds instance to internal hash */
|
||||
int add_instance(Instance *instance);
|
||||
/* inits instances argv's after all options have been loaded */
|
||||
void complete_initialization();
|
||||
int complete_initialization();
|
||||
|
||||
public:
|
||||
const char *mysqld_path;
|
||||
|
@ -74,13 +74,17 @@ err:
|
||||
}
|
||||
|
||||
|
||||
void Instance_options::get_pid_filename(char *result)
|
||||
int Instance_options::get_pid_filename(char *result)
|
||||
{
|
||||
const char *pid_file= mysqld_pid_file;
|
||||
char datadir[MAX_PATH_LEN];
|
||||
|
||||
if (mysqld_datadir == NULL)
|
||||
get_default_option(datadir, sizeof(datadir), "--datadir");
|
||||
{
|
||||
/* we might get an error here if we have wrong path to the mysqld binary */
|
||||
if (get_default_option(datadir, sizeof(datadir), "--datadir"))
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
strxnmov(datadir, MAX_PATH_LEN - 1, strchr(mysqld_datadir, '=') + 1,
|
||||
"/", NullS);
|
||||
@ -90,6 +94,7 @@ void Instance_options::get_pid_filename(char *result)
|
||||
|
||||
/* get the full path to the pidfile */
|
||||
my_load_path(result, pid_file, datadir);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@ -145,7 +150,8 @@ int Instance_options::complete_initialization(const char *default_path)
|
||||
add_option(pidfilename);
|
||||
}
|
||||
|
||||
get_pid_filename(pid_file_with_path);
|
||||
if (get_pid_filename(pid_file_with_path))
|
||||
goto err;
|
||||
|
||||
/* we need to reserve space for the final zero + possible default options */
|
||||
if (!(argv= (char**) alloc_root(&alloc, (options_array.elements + 1
|
||||
|
@ -48,7 +48,7 @@ public:
|
||||
int add_option(const char* option);
|
||||
int init(const char *instance_name_arg);
|
||||
pid_t get_pid();
|
||||
void get_pid_filename(char *result);
|
||||
int get_pid_filename(char *result);
|
||||
int unlink_pidfile();
|
||||
void print_argv();
|
||||
|
||||
|
@ -77,8 +77,18 @@ void manager(const Options &options)
|
||||
|
||||
instance_map.guardian= &guardian_thread;
|
||||
|
||||
if (instance_map.init() || user_map.init() || instance_map.load() ||
|
||||
user_map.load(options.password_file_name))
|
||||
if (instance_map.init() || user_map.init())
|
||||
return;
|
||||
|
||||
if (instance_map.load())
|
||||
{
|
||||
log_error("Cannot init instances repository. This might be caused by "
|
||||
"the wrong config file options. For instance, missing mysqld "
|
||||
"binary. Aborting.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (user_map.load(options.password_file_name))
|
||||
return;
|
||||
|
||||
/* write pid file */
|
||||
@ -173,7 +183,7 @@ void manager(const Options &options)
|
||||
{
|
||||
int status= 0;
|
||||
|
||||
if (status= my_sigwait(&mask, &signo))
|
||||
if ((status= my_sigwait(&mask, &signo)) != 0)
|
||||
{
|
||||
log_error("sigwait() failed");
|
||||
goto err;
|
||||
|
@ -74,7 +74,8 @@ int main(int argc, char *argv[])
|
||||
Options options;
|
||||
struct passwd *user_info;
|
||||
|
||||
options.load(argc, argv);
|
||||
if (options.load(argc, argv))
|
||||
goto err;
|
||||
|
||||
if ((user_info= check_user(options.user)))
|
||||
{
|
||||
@ -96,6 +97,9 @@ int main(int argc, char *argv[])
|
||||
options.cleanup();
|
||||
my_end(0);
|
||||
return 0;
|
||||
err:
|
||||
my_end(0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/******************* Auxilary functions implementation **********************/
|
||||
|
@ -207,14 +207,16 @@ C_MODE_END
|
||||
May not return.
|
||||
*/
|
||||
|
||||
void Options::load(int argc, char **argv)
|
||||
int Options::load(int argc, char **argv)
|
||||
{
|
||||
int rc;
|
||||
/* config-file options are prepended to command-line ones */
|
||||
load_defaults("my", default_groups, &argc, &argv);
|
||||
|
||||
if (int rc= handle_options(&argc, &argv, my_long_options, get_one_option))
|
||||
exit(rc);
|
||||
if (rc= handle_options(&argc, &argv, my_long_options, get_one_option))
|
||||
return rc;
|
||||
Options::saved_argv= argv;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Options::cleanup()
|
||||
|
@ -41,7 +41,7 @@ struct Options
|
||||
|
||||
static char **saved_argv;
|
||||
|
||||
static void load(int argc, char **argv);
|
||||
static int load(int argc, char **argv);
|
||||
void cleanup();
|
||||
};
|
||||
|
||||
|
@ -91,8 +91,8 @@ int parse_output_and_get_value(const char *command, const char *word,
|
||||
}
|
||||
|
||||
pclose:
|
||||
if (pclose(output))
|
||||
return 1;
|
||||
/* we are not interested in the termination status */
|
||||
pclose(output);
|
||||
|
||||
return 0;
|
||||
|
||||
|
Reference in New Issue
Block a user