Commit 4ffd997a authored by unknown's avatar unknown

Bug#28012 Patch : IM crashes instead of reporting an error when mysqldpath is bad

  
On the windows platform, if an instance object failed to initialize during
program start, the instance manager would crash.
This could happen if an incorrect mysqld path was supplied in the 
defaults configuration file.
The patch prevents the program from crashing and makes it show an
error message instead.


mysql-test/r/im_options.result:
  - Options have changed names.
server-tools/instance-manager/instance.cc:
  - Added code to verify that the instance object was initialized
    before any attempt is made to start the associated process.
  - Instance::complete_initialization method will now return TRUE
    on an error during instance initialization.
server-tools/instance-manager/instance_options.cc:
  - Parsed result byte sequence from executed process doesn't contain a new line
    character anymore.
server-tools/instance-manager/parse_output.cc:
  - 'popen' didn't behave as intended on the windows platform.
  - The function parse_output_and_get_value was completly rewritten to correct the
    error in the windows built and to be more easily maintained across platforms.
server-tools/instance-manager/parse_output.h:
  - 'popen' didn't behave as intended on the windows platform.
  - The function parse_output_and_get_value was completly rewritten to correct the
    error in the windows built and to be more easily maintained across platforms.
server-tools/instance-manager/portability.h:
  - Add more portability constants for convenience.
parent be11de7a
...@@ -37,9 +37,10 @@ log-slow-queries option_value ...@@ -37,9 +37,10 @@ log-slow-queries option_value
language option_value language option_value
character-sets-dir option_value character-sets-dir option_value
basedir option_value basedir option_value
shutdown-delay option_value
skip-stack-trace option_value skip-stack-trace option_value
skip-innodb option_value loose-skip-innodb option_value
skip-ndbcluster option_value loose-skip-ndbcluster option_value
nonguarded option_value nonguarded option_value
log-output option_value log-output option_value
SET mysqld2.server_id = 2; SET mysqld2.server_id = 2;
...@@ -57,9 +58,10 @@ log-slow-queries option_value ...@@ -57,9 +58,10 @@ log-slow-queries option_value
language option_value language option_value
character-sets-dir option_value character-sets-dir option_value
basedir option_value basedir option_value
shutdown-delay option_value
skip-stack-trace option_value skip-stack-trace option_value
skip-innodb option_value loose-skip-innodb option_value
skip-ndbcluster option_value loose-skip-ndbcluster option_value
nonguarded option_value nonguarded option_value
log-output option_value log-output option_value
server_id option_value server_id option_value
......
...@@ -524,24 +524,17 @@ bool Instance::init(const LEX_STRING *name_arg) ...@@ -524,24 +524,17 @@ bool Instance::init(const LEX_STRING *name_arg)
/** /**
Complete instance options initialization. @brief Complete instance options initialization.
SYNOPSIS @return Error status.
complete_initialization() @retval FALSE ok
@retval TRUE error
RETURN
FALSE - ok
TRUE - error
*/ */
bool Instance::complete_initialization() bool Instance::complete_initialization()
{ {
configured= ! options.complete_initialization(); configured= ! options.complete_initialization();
return FALSE; return !configured;
/*
TODO: return actual status (from
Instance_options::complete_initialization()) here.
*/
} }
/************************************************************************** /**************************************************************************
...@@ -644,25 +637,24 @@ bool Instance::is_mysqld_running() ...@@ -644,25 +637,24 @@ bool Instance::is_mysqld_running()
/** /**
Start mysqld. @brief Start mysqld.
SYNOPSIS
start_mysqld()
DESCRIPTION
Reset flags and start Instance Monitor thread, which will start mysqld. Reset flags and start Instance Monitor thread, which will start mysqld.
MT-NOTE: instance must be locked before calling the operation. @note Instance must be locked before calling the operation.
RETURN @return Error status code
FALSE - ok @retval FALSE Ok
TRUE - could not start instance @retval TRUE Could not start instance
*/ */
bool Instance::start_mysqld() bool Instance::start_mysqld()
{ {
Instance_monitor *instance_monitor; Instance_monitor *instance_monitor;
if (!configured)
return TRUE;
/* /*
Prepare instance to start Instance Monitor thread. Prepare instance to start Instance Monitor thread.
......
...@@ -156,7 +156,8 @@ int Instance_options::get_default_option(char *result, size_t result_len, ...@@ -156,7 +156,8 @@ int Instance_options::get_default_option(char *result, size_t result_len,
goto err; goto err;
/* +2 eats first "--" from the option string (E.g. "--datadir") */ /* +2 eats first "--" from the option string (E.g. "--datadir") */
rc= parse_output_and_get_value((char*) cmd.buffer, option_name + 2, rc= parse_output_and_get_value((char*) cmd.buffer,
option_name + 2, strlen(option_name + 2),
result, result_len, GET_VALUE); result, result_len, GET_VALUE);
err: err:
return rc; return rc;
...@@ -194,8 +195,8 @@ bool Instance_options::fill_instance_version() ...@@ -194,8 +195,8 @@ bool Instance_options::fill_instance_version()
bzero(result, MAX_VERSION_LENGTH); bzero(result, MAX_VERSION_LENGTH);
if (parse_output_and_get_value((char*) cmd.buffer, "Ver", result, if (parse_output_and_get_value((char*) cmd.buffer, STRING_WITH_LEN("Ver"),
MAX_VERSION_LENGTH, GET_LINE)) result, MAX_VERSION_LENGTH, GET_LINE))
{ {
log_error("Failed to get version of '%s': unexpected output.", log_error("Failed to get version of '%s': unexpected output.",
(const char *) mysqld_path.str); (const char *) mysqld_path.str);
...@@ -206,8 +207,7 @@ bool Instance_options::fill_instance_version() ...@@ -206,8 +207,7 @@ bool Instance_options::fill_instance_version()
{ {
char *start; char *start;
/* chop the newline from the end of the version string */
result[strlen(result) - NEWLINE_LEN]= '\0';
/* trim leading whitespaces */ /* trim leading whitespaces */
start= result; start= result;
while (my_isspace(default_charset_info, *start)) while (my_isspace(default_charset_info, *start))
...@@ -255,7 +255,8 @@ bool Instance_options::fill_mysqld_real_path() ...@@ -255,7 +255,8 @@ bool Instance_options::fill_mysqld_real_path()
bzero(result, FN_REFLEN); bzero(result, FN_REFLEN);
if (parse_output_and_get_value((char*) cmd.buffer, "Usage: ", if (parse_output_and_get_value((char*) cmd.buffer,
STRING_WITH_LEN("Usage: "),
result, FN_REFLEN, result, FN_REFLEN,
GET_LINE)) GET_LINE))
{ {
......
...@@ -17,11 +17,17 @@ ...@@ -17,11 +17,17 @@
#include <my_global.h> #include <my_global.h>
#define GET_VALUE 1 enum enum_option_type
#define GET_LINE 2 {
GET_VALUE = 1,
GET_LINE
};
int parse_output_and_get_value(const char *command, const char *word, bool parse_output_and_get_value(const char *command,
char *result, size_t input_buffer_len, const char *option_name_str,
uint flag); uint option_name_length,
char *option_value_buf,
size_t option_value_buf_size,
enum_option_type option_type);
#endif /* INCLUDES_MYSQL_INSTANCE_MANAGER_PARSE_OUTPUT_H */ #endif /* INCLUDES_MYSQL_INSTANCE_MANAGER_PARSE_OUTPUT_H */
...@@ -48,11 +48,16 @@ typedef int pid_t; ...@@ -48,11 +48,16 @@ typedef int pid_t;
#define NEWLINE "\r\n" #define NEWLINE "\r\n"
#define NEWLINE_LEN 2 #define NEWLINE_LEN 2
const char CR = '\r';
const char LF = '\n';
#else /* ! __WIN__ */ #else /* ! __WIN__ */
#define NEWLINE "\n" #define NEWLINE "\n"
#define NEWLINE_LEN 1 #define NEWLINE_LEN 1
const char LF = '\n';
#endif /* __WIN__ */ #endif /* __WIN__ */
#endif /* INCLUDES_MYSQL_INSTANCE_MANAGER_PORTABILITY_H */ #endif /* INCLUDES_MYSQL_INSTANCE_MANAGER_PORTABILITY_H */
......
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