diff options
author | petr@mysql.com <> | 2004-11-02 10:11:03 +0300 |
---|---|---|
committer | petr@mysql.com <> | 2004-11-02 10:11:03 +0300 |
commit | d3dc041dd157db1e971873a8188ef85fb0f9ecc0 (patch) | |
tree | 73116f6a494156a8064c81fb3da137ffd2210295 /server-tools/instance-manager/instance_options.cc | |
parent | e415866cfef650114d50d0c867c526948a7c1132 (diff) | |
download | mariadb-git-d3dc041dd157db1e971873a8188ef85fb0f9ecc0.tar.gz |
post-review fixes
Diffstat (limited to 'server-tools/instance-manager/instance_options.cc')
-rw-r--r-- | server-tools/instance-manager/instance_options.cc | 115 |
1 files changed, 42 insertions, 73 deletions
diff --git a/server-tools/instance-manager/instance_options.cc b/server-tools/instance-manager/instance_options.cc index 8311e4f7bc0..4f299252bac 100644 --- a/server-tools/instance-manager/instance_options.cc +++ b/server-tools/instance-manager/instance_options.cc @@ -86,90 +86,58 @@ err: int Instance_options::add_option(const char* option) { - uint elements_count=0; - static const char socket[]= "--socket="; - static const char port[]= "--port="; - static const char datadir[]= "--datadir="; - static const char language[]= "--bind-address="; - static const char pid_file[]= "--pid-file="; - static const char path[]= "--mysqld_path="; - static const char user[]= "--admin_user="; - static const char password[]= "--admin_password="; - static const char guarded[]= "--guarded"; char *tmp; - - if (!(tmp= strdup_root(&alloc, option))) - goto err; - - /* To get rid the final zero in a string we subtract 1 from sizeof value */ - if (strncmp(tmp, socket, sizeof socket - 1) == 0) - { - mysqld_socket= tmp; - goto add_options; - } - - if (strncmp(tmp, port, sizeof port - 1) == 0) - { - mysqld_port= tmp; - goto add_options; - } - - if (strncmp(tmp, datadir, sizeof datadir - 1) == 0) - { - mysqld_datadir= tmp; - goto add_options; - } - - if (strncmp(tmp, language, sizeof language - 1) == 0) + enum { SAVE_VALUE= 1, SAVE_WHOLE, SAVE_WHOLE_AND_ADD }; + struct selected_options_st { - mysqld_bind_address= tmp; - goto add_options; - } - - if (strncmp(tmp, pid_file, sizeof pid_file - 1) == 0) + const char *name; + uint length; + const char **value; + uint type; + } options[]= { - mysqld_pid_file= tmp; - goto add_options; - } + {"--socket=", 9, &mysqld_socket, SAVE_WHOLE_AND_ADD}, + {"--port=", 7, &mysqld_port, SAVE_WHOLE_AND_ADD}, + {"--datadir=", 10, &mysqld_datadir, SAVE_WHOLE_AND_ADD}, + {"--bind-address=", 15, &mysqld_bind_address, SAVE_WHOLE_AND_ADD}, + {"--pid-file=", 11, &mysqld_pid_file, SAVE_WHOLE_AND_ADD}, + {"--mysqld_path=", 14, &mysqld_path, SAVE_VALUE}, + {"--admin_user=", 13, &mysqld_user, SAVE_VALUE}, + {"--admin_password=", 17, &mysqld_password, SAVE_VALUE}, + {"--guarded", 9, &is_guarded, SAVE_WHOLE}, + {NULL, 0, NULL, 0} + }; + struct selected_options_st *selected_options; - /* - We don't need a prefix in the next three optios. - We also don't need to add them to argv array => - return instead of goto. - */ - - if (strncmp(tmp, path, sizeof path - 1) == 0) - { - mysqld_path= strchr(tmp, '=') + 1; - return 0; - } - - if (strncmp(tmp, user, sizeof user - 1) == 0) - { - mysqld_user= strchr(tmp, '=') + 1; - return 0; - } - - if (strncmp(tmp, password, sizeof password - 1) == 0) - { - mysqld_password= strchr(tmp, '=') + 1; - return 0; - } + if (!(tmp= strdup_root(&alloc, option))) + goto err; - if (strncmp(tmp, guarded, sizeof guarded - 1) == 0) - { - is_guarded= tmp; - return 0; - } + for (selected_options= options; selected_options->name; selected_options++) + { + if (!strncmp(tmp, selected_options->name, selected_options->length)) + switch(selected_options->type){ + case SAVE_WHOLE_AND_ADD: + *(selected_options->value)= tmp; + insert_dynamic(&options_array,(gptr) &tmp); + return 0; + case SAVE_VALUE: + *(selected_options->value)= strchr(tmp, '=') + 1; + return 0; + case SAVE_WHOLE: + *(selected_options->value)= tmp; + return 0; + defaut: + break; + } + } -add_options: - insert_dynamic(&options_array,(gptr) &tmp); return 0; err: return 1; } + int Instance_options::add_to_argv(const char* option) { DBUG_ASSERT(filled_default_options < MAX_NUMBER_OF_DEFAULT_OPTIONS); @@ -191,7 +159,8 @@ int Instance_options::init(const char *instance_name_arg) init_alloc_root(&alloc, MEM_ROOT_BLOCK_SIZE, 0); - my_init_dynamic_array(&options_array, sizeof(char *), 0, 32); + if (my_init_dynamic_array(&options_array, sizeof(char *), 0, 32)) + goto err; if (!(instance_name= strmake_root(&alloc, (char *) instance_name_arg, instance_name_len))) |