Commit deba12cd authored by unknown's avatar unknown

some more cleanups and fixes


server-tools/instance-manager/commands.cc:
  typo fixed
server-tools/instance-manager/instance.cc:
  moved options.complete_initialization to the instance::complete_initialization
server-tools/instance-manager/instance.h:
  moved options.complete_initialization to the Instance::complete_initialization
server-tools/instance-manager/instance_map.cc:
  moved options.complete_initialization to the Instance::complete_initialization, added code to create
  default instance if none is given iin config. file
server-tools/instance-manager/instance_map.h:
  complete_initialization now returns an error in case of a problem
server-tools/instance-manager/instance_options.cc:
  some error handling added
server-tools/instance-manager/instance_options.h:
  error handling added
server-tools/instance-manager/manager.cc:
  error handling added
server-tools/instance-manager/mysqlmanager.cc:
  stop mysqlmanager if options were not loaded correctly
server-tools/instance-manager/options.cc:
  return-value added
server-tools/instance-manager/options.h:
  return-value added to the OPtions::load()
server-tools/instance-manager/parse_output.cc:
  no need to examine mysqld --help -v termination status
parent 5bd60778
...@@ -276,7 +276,7 @@ int Show_instance_options::do_command(struct st_net *net, ...@@ -276,7 +276,7 @@ int Show_instance_options::do_command(struct st_net *net,
goto err; goto err;
} }
if (instance->options.nonguarded == NULL) if (instance->options.nonguarded != NULL)
{ {
position= 0; position= 0;
store_to_string(&send_buff, (char *) "nonguarded", &position); store_to_string(&send_buff, (char *) "nonguarded", &position);
......
...@@ -296,8 +296,9 @@ int Instance::init(const char *name_arg) ...@@ -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; instance_map= instance_map_arg;
return 0; return options.complete_initialization(mysqld_path);
} }
...@@ -34,7 +34,8 @@ public: ...@@ -34,7 +34,8 @@ public:
~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);
bool is_running(); bool is_running();
int start(); int start();
......
...@@ -74,7 +74,7 @@ static void delete_instance(void *u) ...@@ -74,7 +74,7 @@ static void delete_instance(void *u)
1 - error occured 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_map *map= NULL;
Instance *instance= NULL; Instance *instance= NULL;
...@@ -178,18 +178,41 @@ Instance_map::find(const char *name, uint name_len) ...@@ -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; Instance *instance;
uint i= 0; uint i= 0;
if (hash.records == 0) /* no instances found */
{
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) while (i < hash.records)
{ {
instance= (Instance *) hash_element(&hash, i); instance= (Instance *) hash_element(&hash, i);
instance->complete_initialization(this); if (instance->complete_initialization(this, mysqld_path))
instance->options.complete_initialization(mysqld_path); goto err;
i++; i++;
} }
return 0;
err:
return 1;
err_instance:
delete instance;
return 1;
} }
...@@ -197,13 +220,11 @@ void Instance_map::complete_initialization() ...@@ -197,13 +220,11 @@ void Instance_map::complete_initialization()
int Instance_map::load() int Instance_map::load()
{ {
int error; if (process_default_option_files("my", process_option, (void *) this) ||
complete_initialization())
error= process_default_option_files("my", process_option, (void *) this); return 1;
complete_initialization();
return error; return 0;
} }
......
...@@ -72,7 +72,7 @@ public: ...@@ -72,7 +72,7 @@ public:
/* adds instance to internal hash */ /* adds instance to internal hash */
int add_instance(Instance *instance); int add_instance(Instance *instance);
/* inits instances argv's after all options have been loaded */ /* inits instances argv's after all options have been loaded */
void complete_initialization(); int complete_initialization();
public: public:
const char *mysqld_path; const char *mysqld_path;
......
...@@ -74,13 +74,17 @@ err: ...@@ -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; const char *pid_file= mysqld_pid_file;
char datadir[MAX_PATH_LEN]; char datadir[MAX_PATH_LEN];
if (mysqld_datadir == NULL) 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 else
strxnmov(datadir, MAX_PATH_LEN - 1, strchr(mysqld_datadir, '=') + 1, strxnmov(datadir, MAX_PATH_LEN - 1, strchr(mysqld_datadir, '=') + 1,
"/", NullS); "/", NullS);
...@@ -90,6 +94,7 @@ void Instance_options::get_pid_filename(char *result) ...@@ -90,6 +94,7 @@ void Instance_options::get_pid_filename(char *result)
/* get the full path to the pidfile */ /* get the full path to the pidfile */
my_load_path(result, pid_file, datadir); my_load_path(result, pid_file, datadir);
return 0;
} }
...@@ -145,7 +150,8 @@ int Instance_options::complete_initialization(const char *default_path) ...@@ -145,7 +150,8 @@ int Instance_options::complete_initialization(const char *default_path)
add_option(pidfilename); 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 */ /* we need to reserve space for the final zero + possible default options */
if (!(argv= (char**) alloc_root(&alloc, (options_array.elements + 1 if (!(argv= (char**) alloc_root(&alloc, (options_array.elements + 1
......
...@@ -48,7 +48,7 @@ public: ...@@ -48,7 +48,7 @@ public:
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);
pid_t get_pid(); pid_t get_pid();
void get_pid_filename(char *result); int get_pid_filename(char *result);
int unlink_pidfile(); int unlink_pidfile();
void print_argv(); void print_argv();
......
...@@ -77,8 +77,18 @@ void manager(const Options &options) ...@@ -77,8 +77,18 @@ void manager(const Options &options)
instance_map.guardian= &guardian_thread; instance_map.guardian= &guardian_thread;
if (instance_map.init() || user_map.init() || instance_map.load() || if (instance_map.init() || user_map.init())
user_map.load(options.password_file_name)) 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; return;
/* write pid file */ /* write pid file */
...@@ -173,7 +183,7 @@ void manager(const Options &options) ...@@ -173,7 +183,7 @@ void manager(const Options &options)
{ {
int status= 0; int status= 0;
if (status= my_sigwait(&mask, &signo)) if ((status= my_sigwait(&mask, &signo)) != 0)
{ {
log_error("sigwait() failed"); log_error("sigwait() failed");
goto err; goto err;
......
...@@ -74,7 +74,8 @@ int main(int argc, char *argv[]) ...@@ -74,7 +74,8 @@ int main(int argc, char *argv[])
Options options; Options options;
struct passwd *user_info; struct passwd *user_info;
options.load(argc, argv); if (options.load(argc, argv))
goto err;
if ((user_info= check_user(options.user))) if ((user_info= check_user(options.user)))
{ {
...@@ -96,6 +97,9 @@ int main(int argc, char *argv[]) ...@@ -96,6 +97,9 @@ int main(int argc, char *argv[])
options.cleanup(); options.cleanup();
my_end(0); my_end(0);
return 0; return 0;
err:
my_end(0);
return 1;
} }
/******************* Auxilary functions implementation **********************/ /******************* Auxilary functions implementation **********************/
......
...@@ -207,14 +207,16 @@ C_MODE_END ...@@ -207,14 +207,16 @@ C_MODE_END
May not return. 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 */ /* config-file options are prepended to command-line ones */
load_defaults("my", default_groups, &argc, &argv); load_defaults("my", default_groups, &argc, &argv);
if (int rc= handle_options(&argc, &argv, my_long_options, get_one_option)) if (rc= handle_options(&argc, &argv, my_long_options, get_one_option))
exit(rc); return rc;
Options::saved_argv= argv; Options::saved_argv= argv;
return 0;
} }
void Options::cleanup() void Options::cleanup()
......
...@@ -41,7 +41,7 @@ struct Options ...@@ -41,7 +41,7 @@ struct Options
static char **saved_argv; static char **saved_argv;
static void load(int argc, char **argv); static int load(int argc, char **argv);
void cleanup(); void cleanup();
}; };
......
...@@ -91,8 +91,8 @@ int parse_output_and_get_value(const char *command, const char *word, ...@@ -91,8 +91,8 @@ int parse_output_and_get_value(const char *command, const char *word,
} }
pclose: pclose:
if (pclose(output)) /* we are not interested in the termination status */
return 1; pclose(output);
return 0; return 0;
......
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