diff options
author | petr@mysql.com <> | 2005-02-15 04:38:33 +0300 |
---|---|---|
committer | petr@mysql.com <> | 2005-02-15 04:38:33 +0300 |
commit | 59d8e51150faa3aeaf489c4454fd6780ad849239 (patch) | |
tree | 11422217e66ff042bc75eb00563d6c7b1f36e26f /server-tools | |
parent | bb8e5b6227ef83b67fd9a786bd32768231d42bdb (diff) | |
download | mariadb-git-59d8e51150faa3aeaf489c4454fd6780ad849239.tar.gz |
some more cleanups and fixes
Diffstat (limited to 'server-tools')
-rw-r--r-- | server-tools/instance-manager/commands.cc | 2 | ||||
-rw-r--r-- | server-tools/instance-manager/instance.cc | 5 | ||||
-rw-r--r-- | server-tools/instance-manager/instance.h | 3 | ||||
-rw-r--r-- | server-tools/instance-manager/instance_map.cc | 47 | ||||
-rw-r--r-- | server-tools/instance-manager/instance_map.h | 2 | ||||
-rw-r--r-- | server-tools/instance-manager/instance_options.cc | 12 | ||||
-rw-r--r-- | server-tools/instance-manager/instance_options.h | 2 | ||||
-rw-r--r-- | server-tools/instance-manager/manager.cc | 16 | ||||
-rw-r--r-- | server-tools/instance-manager/mysqlmanager.cc | 6 | ||||
-rw-r--r-- | server-tools/instance-manager/options.cc | 8 | ||||
-rw-r--r-- | server-tools/instance-manager/options.h | 2 | ||||
-rw-r--r-- | server-tools/instance-manager/parse_output.cc | 4 |
12 files changed, 77 insertions, 32 deletions
diff --git a/server-tools/instance-manager/commands.cc b/server-tools/instance-manager/commands.cc index 4667e76bfd6..4e88f358148 100644 --- a/server-tools/instance-manager/commands.cc +++ b/server-tools/instance-manager/commands.cc @@ -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); diff --git a/server-tools/instance-manager/instance.cc b/server-tools/instance-manager/instance.cc index e654612de3e..f2140ee7200 100644 --- a/server-tools/instance-manager/instance.cc +++ b/server-tools/instance-manager/instance.cc @@ -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); } diff --git a/server-tools/instance-manager/instance.h b/server-tools/instance-manager/instance.h index fbe24e17554..d2a3eb98410 100644 --- a/server-tools/instance-manager/instance.h +++ b/server-tools/instance-manager/instance.h @@ -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(); diff --git a/server-tools/instance-manager/instance_map.cc b/server-tools/instance-manager/instance_map.cc index 5044bfb0f43..191677889e9 100644 --- a/server-tools/instance-manager/instance_map.cc +++ b/server-tools/instance-manager/instance_map.cc @@ -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; - - error= process_default_option_files("my", process_option, (void *) this); - - complete_initialization(); + if (process_default_option_files("my", process_option, (void *) this) || + complete_initialization()) + return 1; - return error; + return 0; } diff --git a/server-tools/instance-manager/instance_map.h b/server-tools/instance-manager/instance_map.h index b8b5ad0a890..60fde43ce12 100644 --- a/server-tools/instance-manager/instance_map.h +++ b/server-tools/instance-manager/instance_map.h @@ -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; diff --git a/server-tools/instance-manager/instance_options.cc b/server-tools/instance-manager/instance_options.cc index 7c41a556cc4..6b795934d08 100644 --- a/server-tools/instance-manager/instance_options.cc +++ b/server-tools/instance-manager/instance_options.cc @@ -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 diff --git a/server-tools/instance-manager/instance_options.h b/server-tools/instance-manager/instance_options.h index f6d4a6d93c6..888658969f2 100644 --- a/server-tools/instance-manager/instance_options.h +++ b/server-tools/instance-manager/instance_options.h @@ -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(); diff --git a/server-tools/instance-manager/manager.cc b/server-tools/instance-manager/manager.cc index 87ad938615f..cf7820d0335 100644 --- a/server-tools/instance-manager/manager.cc +++ b/server-tools/instance-manager/manager.cc @@ -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; diff --git a/server-tools/instance-manager/mysqlmanager.cc b/server-tools/instance-manager/mysqlmanager.cc index e37dab911c1..e1d267b492e 100644 --- a/server-tools/instance-manager/mysqlmanager.cc +++ b/server-tools/instance-manager/mysqlmanager.cc @@ -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 **********************/ diff --git a/server-tools/instance-manager/options.cc b/server-tools/instance-manager/options.cc index 18d98a3d9a6..b136ae3c386 100644 --- a/server-tools/instance-manager/options.cc +++ b/server-tools/instance-manager/options.cc @@ -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() diff --git a/server-tools/instance-manager/options.h b/server-tools/instance-manager/options.h index bb6da51d1ca..1b8570dd7ba 100644 --- a/server-tools/instance-manager/options.h +++ b/server-tools/instance-manager/options.h @@ -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(); }; diff --git a/server-tools/instance-manager/parse_output.cc b/server-tools/instance-manager/parse_output.cc index 317970d2047..58e3fbf9fbd 100644 --- a/server-tools/instance-manager/parse_output.cc +++ b/server-tools/instance-manager/parse_output.cc @@ -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; |