mirror of
https://github.com/MariaDB/server.git
synced 2026-05-15 19:37:16 +02:00
merge
BitKeeper/etc/logging_ok: auto-union sql/mysqld.cc: Auto merged sql/sql_class.h: Auto merged sql/sql_lex.cc: Auto merged sql/sql_lex.h: Auto merged sql/sql_parse.cc: Auto merged sql/sql_repl.cc: Auto merged sql/sql_select.cc: Auto merged sql/sql_yacc.yy: Auto merged storage/myisam/mi_key.c: Auto merged storage/myisam/mi_rnext_same.c: Auto merged support-files/mysql.spec.sh: Auto merged
This commit is contained in:
commit
95caf68315
51 changed files with 506 additions and 250 deletions
|
|
@ -52,7 +52,7 @@ public:
|
|||
|
||||
~Buffer()
|
||||
{
|
||||
free(buffer);
|
||||
my_free(buffer, MYF(0));
|
||||
}
|
||||
|
||||
public:
|
||||
|
|
|
|||
|
|
@ -203,15 +203,14 @@ int Show_instance_status::execute(struct st_net *net,
|
|||
if (!(instance= instance_map->find(instance_name, strlen(instance_name))))
|
||||
goto err;
|
||||
if (instance->is_running())
|
||||
{
|
||||
store_to_string(&send_buff, (char*) "online", &position);
|
||||
store_to_string(&send_buff, "unknown", &position);
|
||||
}
|
||||
else
|
||||
{
|
||||
store_to_string(&send_buff, (char*) "offline", &position);
|
||||
|
||||
if (instance->options.mysqld_version)
|
||||
store_to_string(&send_buff, instance->options.mysqld_version, &position);
|
||||
else
|
||||
store_to_string(&send_buff, (char*) "unknown", &position);
|
||||
}
|
||||
|
||||
|
||||
if (send_buff.is_error() ||
|
||||
|
|
@ -645,10 +644,6 @@ Set_option::Set_option(Instance_map *instance_map_arg,
|
|||
{
|
||||
strmake(option, option_arg, option_len_arg);
|
||||
strmake(option_value, option_value_arg, option_value_len_arg);
|
||||
/* strncpy(option, option_arg, option_len_arg);
|
||||
option[option_len_arg]= 0;
|
||||
strncpy(option_value, option_value_arg, option_value_len_arg);
|
||||
option_value[option_value_len_arg]= 0; */
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
|
|
@ -326,8 +326,8 @@ int Instance::init(const char *name_arg)
|
|||
|
||||
int Instance::complete_initialization(Instance_map *instance_map_arg,
|
||||
const char *mysqld_path,
|
||||
int only_instance)
|
||||
uint instance_type)
|
||||
{
|
||||
instance_map= instance_map_arg;
|
||||
return options.complete_initialization(mysqld_path, only_instance);
|
||||
return options.complete_initialization(mysqld_path, instance_type);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ public:
|
|||
~Instance();
|
||||
int init(const char *name);
|
||||
int complete_initialization(Instance_map *instance_map_arg,
|
||||
const char *mysqld_path, int only_instance= 0);
|
||||
const char *mysqld_path, uint instance_type);
|
||||
|
||||
bool is_running();
|
||||
int start();
|
||||
|
|
|
|||
|
|
@ -202,14 +202,14 @@ int Instance_map::complete_initialization()
|
|||
hash_free should handle it's deletion => goto err, not
|
||||
err_instance.
|
||||
*/
|
||||
if (instance->complete_initialization(this, mysqld_path, 1))
|
||||
if (instance->complete_initialization(this, mysqld_path, DEFAULT_SINGLE_INSTANCE))
|
||||
goto err;
|
||||
}
|
||||
else
|
||||
while (i < hash.records)
|
||||
{
|
||||
instance= (Instance *) hash_element(&hash, i);
|
||||
if (instance->complete_initialization(this, mysqld_path))
|
||||
if (instance->complete_initialization(this, mysqld_path, USUAL_INSTANCE))
|
||||
goto err;
|
||||
i++;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,6 +27,39 @@
|
|||
#include <signal.h>
|
||||
#include <m_string.h>
|
||||
|
||||
#ifdef __WIN__
|
||||
#define NEWLINE_LEN 2
|
||||
#else
|
||||
#define NEWLINE_LEN 1
|
||||
#endif
|
||||
|
||||
|
||||
/* Create "mysqld ..." command in the buffer */
|
||||
|
||||
static inline int create_mysqld_command(Buffer *buf,
|
||||
const char *mysqld_path_str,
|
||||
uint mysqld_path_len,
|
||||
const char *option,
|
||||
uint option_len)
|
||||
{
|
||||
int position= 0;
|
||||
|
||||
if (buf->get_size()) /* malloc succeeded */
|
||||
{
|
||||
buf->append(position, mysqld_path_str, mysqld_path_len);
|
||||
position+= mysqld_path_len;
|
||||
/* here the '\0' character is copied from the option string */
|
||||
buf->append(position, option, option_len);
|
||||
|
||||
if (buf->is_error())
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Get compiled-in value of default_option
|
||||
|
|
@ -50,25 +83,19 @@
|
|||
int Instance_options::get_default_option(char *result, size_t result_len,
|
||||
const char *option_name)
|
||||
{
|
||||
int position= 0;
|
||||
int rc= 1;
|
||||
char verbose_option[]= " --no-defaults --verbose --help";
|
||||
|
||||
Buffer cmd(strlen(mysqld_path) + sizeof(verbose_option) + 1);
|
||||
if (cmd.get_size()) /* malloc succeeded */
|
||||
{
|
||||
cmd.append(position, mysqld_path, strlen(mysqld_path));
|
||||
position+= strlen(mysqld_path);
|
||||
cmd.append(position, verbose_option, sizeof(verbose_option) - 1);
|
||||
position+= sizeof(verbose_option) - 1;
|
||||
cmd.append(position, "\0", 1);
|
||||
/* reserve space fot the path + option + final '\0' */
|
||||
Buffer cmd(mysqld_path_len + sizeof(verbose_option));
|
||||
|
||||
if (cmd.is_error())
|
||||
goto err;
|
||||
/* get the value from "mysqld --help --verbose" */
|
||||
rc= parse_output_and_get_value(cmd.buffer, option_name + 2,
|
||||
result, result_len);
|
||||
}
|
||||
if (create_mysqld_command(&cmd, mysqld_path, mysqld_path_len,
|
||||
verbose_option, sizeof(verbose_option)))
|
||||
goto err;
|
||||
|
||||
/* +2 eats first "--" from the option string (E.g. "--datadir") */
|
||||
rc= parse_output_and_get_value(cmd.buffer, option_name + 2,
|
||||
result, result_len, GET_VALUE);
|
||||
|
||||
return rc;
|
||||
err:
|
||||
|
|
@ -77,17 +104,61 @@ err:
|
|||
|
||||
|
||||
/*
|
||||
Get compiled-in value of default_option
|
||||
Fill mysqld_version option (used at initialization stage)
|
||||
|
||||
SYNOPSYS
|
||||
get_default_option()
|
||||
result buffer to put found value
|
||||
result_len buffer size
|
||||
option_name the name of the option, prefixed with "--"
|
||||
fill_instance_version()
|
||||
|
||||
DESCRIPTION
|
||||
|
||||
Get compile-in value of requested option from server
|
||||
Get mysqld version string from "mysqld --version" output.
|
||||
|
||||
RETURN
|
||||
0 - ok
|
||||
1 - error occured
|
||||
*/
|
||||
|
||||
int Instance_options::fill_instance_version()
|
||||
{
|
||||
enum { MAX_VERSION_STRING_LENGTH= 160 };
|
||||
char result[MAX_VERSION_STRING_LENGTH];
|
||||
char version_option[]= " --no-defaults --version";
|
||||
int rc= 1;
|
||||
Buffer cmd(mysqld_path_len + sizeof(version_option));
|
||||
|
||||
if (create_mysqld_command(&cmd, mysqld_path, mysqld_path_len,
|
||||
version_option, sizeof(version_option)))
|
||||
goto err;
|
||||
|
||||
rc= parse_output_and_get_value(cmd.buffer, mysqld_path,
|
||||
result, MAX_VERSION_STRING_LENGTH,
|
||||
GET_LINE);
|
||||
|
||||
if (*result != '\0')
|
||||
{
|
||||
/* chop the newline from the end of the version string */
|
||||
result[strlen(result) - NEWLINE_LEN]= '\0';
|
||||
mysqld_version= strdup_root(&alloc, result);
|
||||
}
|
||||
|
||||
return rc;
|
||||
|
||||
err:
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Fill various log options
|
||||
|
||||
SYNOPSYS
|
||||
fill_log_options()
|
||||
|
||||
DESCRIPTION
|
||||
|
||||
Compute paths to enabled log files. If the path is not specified in the
|
||||
instance explicitly (I.e. log=/home/user/mysql.log), we try to guess the
|
||||
file name and placement.
|
||||
|
||||
RETURN
|
||||
0 - ok
|
||||
|
|
@ -126,8 +197,8 @@ int Instance_options::fill_log_options()
|
|||
goto err;
|
||||
}
|
||||
else /* below is safe, as --datadir always has a value */
|
||||
strncpy(datadir, strchr(mysqld_datadir, '=') + 1,
|
||||
MAX_LOG_OPTION_LENGTH);
|
||||
strmake(datadir, strchr(mysqld_datadir, '=') + 1,
|
||||
MAX_LOG_OPTION_LENGTH - 1);
|
||||
|
||||
if (gethostname(hostname,sizeof(hostname)-1) < 0)
|
||||
strmov(hostname, "mysql");
|
||||
|
|
@ -160,7 +231,7 @@ int Instance_options::fill_log_options()
|
|||
if ((MAX_LOG_OPTION_LENGTH - strlen(full_name)) >
|
||||
strlen(log_files->default_suffix))
|
||||
{
|
||||
strcpy(full_name + strlen(full_name),
|
||||
strmov(full_name + strlen(full_name),
|
||||
log_files->default_suffix);
|
||||
}
|
||||
else
|
||||
|
|
@ -266,7 +337,7 @@ pid_t Instance_options::get_pid()
|
|||
|
||||
|
||||
int Instance_options::complete_initialization(const char *default_path,
|
||||
int only_instance)
|
||||
uint instance_type)
|
||||
{
|
||||
const char *tmp;
|
||||
|
||||
|
|
@ -276,6 +347,8 @@ int Instance_options::complete_initialization(const char *default_path,
|
|||
goto err;
|
||||
}
|
||||
|
||||
mysqld_path_len= strlen(mysqld_path);
|
||||
|
||||
if (mysqld_port)
|
||||
mysqld_port_val= atoi(strchr(mysqld_port, '=') + 1);
|
||||
|
||||
|
|
@ -295,18 +368,23 @@ int Instance_options::complete_initialization(const char *default_path,
|
|||
found, we would like to model mysqld pid file values.
|
||||
*/
|
||||
if (!gethostname(hostname, sizeof(hostname) - 1))
|
||||
(only_instance == 0) ?
|
||||
strxnmov(pidfilename, MAX_PATH_LEN - 1, "--pid-file=", instance_name, "-",
|
||||
hostname, ".pid", NullS):
|
||||
strxnmov(pidfilename, MAX_PATH_LEN - 1, "--pid-file=", hostname,
|
||||
".pid", NullS);
|
||||
|
||||
{
|
||||
if (instance_type & DEFAULT_SINGLE_INSTANCE)
|
||||
strxnmov(pidfilename, MAX_PATH_LEN - 1, "--pid-file=", hostname,
|
||||
".pid", NullS);
|
||||
else
|
||||
strxnmov(pidfilename, MAX_PATH_LEN - 1, "--pid-file=", instance_name,
|
||||
"-", hostname, ".pid", NullS);
|
||||
}
|
||||
else
|
||||
(only_instance == 0) ?
|
||||
strxnmov(pidfilename, MAX_PATH_LEN - 1, "--pid-file=", instance_name,
|
||||
".pid", NullS):
|
||||
strxnmov(pidfilename, MAX_PATH_LEN - 1, "--pid-file=", "mysql",
|
||||
".pid", NullS);
|
||||
{
|
||||
if (instance_type & DEFAULT_SINGLE_INSTANCE)
|
||||
strxnmov(pidfilename, MAX_PATH_LEN - 1, "--pid-file=", "mysql",
|
||||
".pid", NullS);
|
||||
else
|
||||
strxnmov(pidfilename, MAX_PATH_LEN - 1, "--pid-file=", instance_name,
|
||||
".pid", NullS);
|
||||
}
|
||||
|
||||
add_option(pidfilename);
|
||||
}
|
||||
|
|
@ -330,7 +408,8 @@ int Instance_options::complete_initialization(const char *default_path,
|
|||
options_array.elements*sizeof(char*));
|
||||
argv[filled_default_options + options_array.elements]= 0;
|
||||
|
||||
fill_log_options();
|
||||
if (fill_log_options() || fill_instance_version())
|
||||
goto err;
|
||||
|
||||
return 0;
|
||||
|
||||
|
|
|
|||
|
|
@ -34,18 +34,21 @@
|
|||
don't have to synchronize between threads.
|
||||
*/
|
||||
|
||||
#define USUAL_INSTANCE 0
|
||||
#define DEFAULT_SINGLE_INSTANCE 1
|
||||
|
||||
class Instance_options
|
||||
{
|
||||
public:
|
||||
Instance_options() :
|
||||
mysqld_socket(0), mysqld_datadir(0),
|
||||
mysqld_version(0), mysqld_socket(0), mysqld_datadir(0),
|
||||
mysqld_bind_address(0), mysqld_pid_file(0), mysqld_port(0),
|
||||
mysqld_port_val(0), mysqld_path(0), nonguarded(0), shutdown_delay(0),
|
||||
shutdown_delay_val(0), filled_default_options(0)
|
||||
{}
|
||||
~Instance_options();
|
||||
/* fills in argv */
|
||||
int complete_initialization(const char *default_path, int only_instance);
|
||||
int complete_initialization(const char *default_path, uint instance_type);
|
||||
|
||||
int add_option(const char* option);
|
||||
int init(const char *instance_name_arg);
|
||||
|
|
@ -64,6 +67,11 @@ public:
|
|||
enum { MEM_ROOT_BLOCK_SIZE= 512 };
|
||||
char pid_file_with_path[MAX_PATH_LEN];
|
||||
char **argv;
|
||||
/*
|
||||
Here we cache the version string, obtained from mysqld --version.
|
||||
In the case when mysqld binary is not found we get NULL here.
|
||||
*/
|
||||
const char *mysqld_version;
|
||||
/* We need the some options, so we store them as a separate pointers */
|
||||
const char *mysqld_socket;
|
||||
const char *mysqld_datadir;
|
||||
|
|
@ -74,6 +82,7 @@ public:
|
|||
const char *instance_name;
|
||||
uint instance_name_len;
|
||||
const char *mysqld_path;
|
||||
uint mysqld_path_len;
|
||||
const char *nonguarded;
|
||||
const char *shutdown_delay;
|
||||
uint shutdown_delay_val;
|
||||
|
|
@ -84,6 +93,7 @@ public:
|
|||
DYNAMIC_ARRAY options_array;
|
||||
private:
|
||||
int fill_log_options();
|
||||
int fill_instance_version();
|
||||
int add_to_argv(const char *option);
|
||||
int get_default_option(char *result, size_t result_len,
|
||||
const char *option_name);
|
||||
|
|
|
|||
|
|
@ -163,7 +163,7 @@ void Listener_thread::run()
|
|||
unix_socket_address.sun_family= AF_UNIX;
|
||||
strmake(unix_socket_address.sun_path, options.socket_file_name,
|
||||
sizeof(unix_socket_address.sun_path));
|
||||
unlink(unix_socket_address.sun_path); // in case we have stale socket file
|
||||
unlink(unix_socket_address.sun_path); /* in case we have stale socket file */
|
||||
|
||||
{
|
||||
/*
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ static inline void log(FILE *file, const char *format, va_list args)
|
|||
if (buff_msg == 0)
|
||||
{
|
||||
strmake(buff_stack, "log(): message is too big, my_malloc() failed",
|
||||
sizeof(buff_stack));
|
||||
sizeof(buff_stack) - 1);
|
||||
buff_msg= buff_stack;
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -224,10 +224,10 @@ int Options::load(int argc, char **argv)
|
|||
|
||||
/* config-file options are prepended to command-line ones */
|
||||
load_defaults("my", default_groups, &argc, &argv);
|
||||
Options::saved_argv= argv;
|
||||
|
||||
if ((rc= handle_options(&argc, &argv, my_long_options, get_one_option)) != 0)
|
||||
return rc;
|
||||
Options::saved_argv= argv;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,10 +16,11 @@
|
|||
|
||||
#include <my_global.h>
|
||||
#include "parse.h"
|
||||
#include "parse_output.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <my_sys.h>
|
||||
#include <string.h>
|
||||
#include <m_string.h>
|
||||
|
||||
|
||||
/*
|
||||
|
|
@ -28,14 +29,17 @@
|
|||
SYNOPSYS
|
||||
parse_output_and_get_value()
|
||||
|
||||
command the command to execue with popen.
|
||||
word the word to look for (usually an option name)
|
||||
result the buffer to store the next word (option value)
|
||||
result_len self-explanatory
|
||||
command the command to execue with popen.
|
||||
word the word to look for (usually an option name)
|
||||
result the buffer to store the next word (option value)
|
||||
input_buffer_len self-explanatory
|
||||
flag this equals to GET_LINE if we want to get all the line after
|
||||
the matched word and GET_VALUE otherwise.
|
||||
|
||||
DESCRIPTION
|
||||
|
||||
Parse output of the "command". Find the "word" and return the next one
|
||||
if flag is GET_VALUE. Return the rest of the parsed string otherwise.
|
||||
|
||||
RETURN
|
||||
0 - ok
|
||||
|
|
@ -43,7 +47,8 @@
|
|||
*/
|
||||
|
||||
int parse_output_and_get_value(const char *command, const char *word,
|
||||
char *result, size_t result_len)
|
||||
char *result, size_t input_buffer_len,
|
||||
uint flag)
|
||||
{
|
||||
FILE *output;
|
||||
uint wordlen;
|
||||
|
|
@ -64,7 +69,7 @@ int parse_output_and_get_value(const char *command, const char *word,
|
|||
|
||||
while (fgets(linebuf, sizeof(linebuf) - 1, output))
|
||||
{
|
||||
uint lineword_len= 0;
|
||||
uint found_word_len= 0;
|
||||
char *linep= linebuf;
|
||||
|
||||
linebuf[sizeof(linebuf) - 1]= '\0'; /* safety */
|
||||
|
|
@ -73,19 +78,25 @@ int parse_output_and_get_value(const char *command, const char *word,
|
|||
Get the word, which might contain non-alphanumeric characters. (Usually
|
||||
these are '/', '-' and '.' in the path expressions and filenames)
|
||||
*/
|
||||
get_word((const char **) &linep, &lineword_len, NONSPACE);
|
||||
get_word((const char **) &linep, &found_word_len, NONSPACE);
|
||||
if (!strncmp(word, linep, wordlen))
|
||||
{
|
||||
/*
|
||||
If we have found the word, return the next one. This is usually
|
||||
an option value.
|
||||
If we have found the word, return the next one (this is usually
|
||||
an option value) or the whole line (if flag)
|
||||
*/
|
||||
linep+= lineword_len; /* swallow the previous one */
|
||||
get_word((const char **) &linep, &lineword_len, NONSPACE);
|
||||
if (result_len <= lineword_len)
|
||||
goto err;
|
||||
strncpy(result, linep, lineword_len);
|
||||
result[lineword_len]= '\0';
|
||||
linep+= found_word_len; /* swallow the previous one */
|
||||
if (flag & GET_VALUE)
|
||||
{
|
||||
get_word((const char **) &linep, &found_word_len, NONSPACE);
|
||||
if (input_buffer_len <= found_word_len)
|
||||
goto err;
|
||||
strmake(result, linep, found_word_len);
|
||||
}
|
||||
else /* currently there are only two options */
|
||||
{
|
||||
strmake(result, linep, input_buffer_len - 1);
|
||||
}
|
||||
goto pclose;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,11 @@
|
|||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
||||
|
||||
#define GET_VALUE 1
|
||||
#define GET_LINE 2
|
||||
|
||||
int parse_output_and_get_value(const char *command, const char *word,
|
||||
char *result, size_t result_len);
|
||||
char *result, size_t input_buffer_len,
|
||||
uint flag);
|
||||
|
||||
#endif /* INCLUDES_MYSQL_INSTANCE_MANAGER_PARSE_OUTPUT_H */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue