Commit 6b4dbcb4 authored by unknown's avatar unknown

post-review fixes


include/my_sys.h:
  added prototype for the defaults correction function
libmysql/Makefile.shared:
  my_chsize added to libmysql to let my_correct_defaults_file be used from libmysql
mysys/default.c:
  New defaults function added we use it to correct defaults file. Currently the function doesn't lock defaults
  file. This is because of the linking and backwards-compatibility issues. This needs to be fixed later.
mysys/my_chsize.c:
  comment added
server-tools/instance-manager/buffer.cc:
  cleanup
server-tools/instance-manager/commands.cc:
  refactoring: removed do_command method from most of the classes
server-tools/instance-manager/commands.h:
  cleanup
server-tools/instance-manager/guardian.cc:
  cleanup
server-tools/instance-manager/instance.cc:
  cleanup
server-tools/instance-manager/instance_map.cc:
  cleanup
server-tools/instance-manager/instance_options.cc:
  cleanup
server-tools/instance-manager/instance_options.h:
  cleanup
server-tools/instance-manager/listener.cc:
  cleanup
server-tools/instance-manager/log.cc:
  cleanup
server-tools/instance-manager/manager.cc:
  cleanup
server-tools/instance-manager/messages.cc:
  new errors added
server-tools/instance-manager/mysql_connection.cc:
  cleanup
server-tools/instance-manager/mysql_manager_error.h:
  new error codes added
server-tools/instance-manager/mysqlmanager.cc:
  clenup
server-tools/instance-manager/options.cc:
  cleanup
server-tools/instance-manager/parse.cc:
  removed unused function
server-tools/instance-manager/parse.h:
  removed prototype
server-tools/instance-manager/protocol.cc:
  cleanup
server-tools/instance-manager/protocol.h:
  added enum to be used in protocol.cc instead of the constants
parent 1ad379af
...@@ -773,6 +773,11 @@ extern void reset_root_defaults(MEM_ROOT *mem_root, uint block_size, ...@@ -773,6 +773,11 @@ extern void reset_root_defaults(MEM_ROOT *mem_root, uint block_size,
extern char *strdup_root(MEM_ROOT *root,const char *str); extern char *strdup_root(MEM_ROOT *root,const char *str);
extern char *strmake_root(MEM_ROOT *root,const char *str,uint len); extern char *strmake_root(MEM_ROOT *root,const char *str,uint len);
extern char *memdup_root(MEM_ROOT *root,const char *str,uint len); extern char *memdup_root(MEM_ROOT *root,const char *str,uint len);
extern int my_correct_defaults_file(const char *file_location,
const char *option,
const char *option_value,
const char *section_name,
int remove_option);
extern void get_defaults_files(int argc, char **argv, extern void get_defaults_files(int argc, char **argv,
char **defaults, char **extra_defaults); char **defaults, char **extra_defaults);
extern int load_defaults(const char *conf_file, const char **groups, extern int load_defaults(const char *conf_file, const char **groups,
......
...@@ -67,7 +67,7 @@ mysysobjects1 = my_init.lo my_static.lo my_malloc.lo my_realloc.lo \ ...@@ -67,7 +67,7 @@ mysysobjects1 = my_init.lo my_static.lo my_malloc.lo my_realloc.lo \
mf_iocache2.lo my_seek.lo my_sleep.lo \ mf_iocache2.lo my_seek.lo my_sleep.lo \
my_pread.lo mf_cache.lo md5.lo sha1.lo \ my_pread.lo mf_cache.lo md5.lo sha1.lo \
my_getopt.lo my_gethostbyname.lo my_port.lo \ my_getopt.lo my_gethostbyname.lo my_port.lo \
my_rename.lo my_rename.lo my_chsize.lo
sqlobjects = net.lo sqlobjects = net.lo
sql_cmn_objects = pack.lo client.lo my_time.lo sql_cmn_objects = pack.lo client.lo my_time.lo
......
...@@ -50,8 +50,10 @@ const char *default_directories[MAX_DEFAULT_DIRS + 1]; ...@@ -50,8 +50,10 @@ const char *default_directories[MAX_DEFAULT_DIRS + 1];
#ifdef __WIN__ #ifdef __WIN__
static const char *f_extensions[]= { ".ini", ".cnf", 0 }; static const char *f_extensions[]= { ".ini", ".cnf", 0 };
#define NEWLINE "\r\n"
#else #else
static const char *f_extensions[]= { ".cnf", 0 }; static const char *f_extensions[]= { ".cnf", 0 };
#define NEWLINE "\n"
#endif #endif
/* /*
...@@ -78,6 +80,142 @@ static void init_default_directories(); ...@@ -78,6 +80,142 @@ static void init_default_directories();
static char *remove_end_comment(char *ptr); static char *remove_end_comment(char *ptr);
/*
Add/remove option to the option file section.
SYNOPSYS
my_correct_file()
file_location The location of configuration file to edit
option option to look for
option value The value of the option we would like to set
section_name the name of the section
remove_option This is true if we want to remove the option.
False otherwise.
IMPLEMENTATION
We open the option file first, then read the file line-by-line,
looking for the section we need. At the same time we put these lines
into a buffer. Then we look for the option within this section and
change/remove it. In the end we get a buffer with modified version of the
file. Then we write it to the file, truncate it if needed and close it.
RETURN
0 - ok
1 - some error has occured. Probably due to the lack of resourses
-1 - cannot open the file
*/
int my_correct_defaults_file(const char *file_location, const char *option,
const char *option_value,
const char *section_name, int remove_option)
{
FILE *cnf_file;
struct stat file_stat;
char linebuff[512], *ptr;
uint optlen;
uint len;
char *file_buffer;
uint position= 0;
int is_found= FALSE;
optlen= strlen(option);
DBUG_ENTER("my_correct_file");
if (!(cnf_file= my_fopen(file_location, O_RDWR, MYF(0))))
goto err_fopen;
/* my_fstat doesn't use the flag parameter */
if (my_fstat(fileno(cnf_file), &file_stat, MYF(0)))
goto err;
/*
Reserve space to read the contents of the file and some more
for the option we want ot add.
*/
file_buffer= (char*) my_malloc(sizeof(char)*
(file_stat.st_size + /* current file size */
optlen + /* option name len */
2 + /* reserve space for newline */
1 + /* reserve for '=' char */
strlen(option_value)), /* option value len */
MYF(MY_WME));
if (!file_buffer)
goto malloc_err;
while (fgets(linebuff, sizeof(linebuff), cnf_file))
{
len= strlen(linebuff);
/* if the section is found traverse it */
if (is_found)
{
/* skip the old value of the option we are changing */
if (strncmp(linebuff, option, optlen))
{
/* copy all other lines */
strmake(file_buffer + position, linebuff, len);
position+= len;
}
}
else
{
strmake(file_buffer + position, linebuff, len);
position+= len;
}
/* looking for appropriate section */
for (ptr= linebuff ; my_isspace(&my_charset_latin1,*ptr) ; ptr++)
{}
if (*ptr == '[')
{
/* copy the line to the buffer */
if (!strncmp(++ptr, section_name, strlen(section_name)))
{
is_found= TRUE;
/* add option */
if (!remove_option)
{
strmake(file_buffer + position, option, optlen);
position+= optlen;
if (*option_value)
{
*(file_buffer + position++)= '=';
strmake(file_buffer + position, option_value,
strlen(option_value));
position+= strlen(option_value);
}
/* add a newline */
strcat(file_buffer + position, NEWLINE);
position+= strlen(NEWLINE);
}
}
else
is_found= FALSE; /* mark that this section is of no interest to us */
}
}
if (my_chsize(fileno(cnf_file), position, 0, MYF(MY_WME)) ||
my_fseek(cnf_file, 0, MY_SEEK_SET, MYF(0)) ||
my_fwrite(cnf_file, file_buffer, position, MYF(MY_NABP)) ||
my_fclose(cnf_file, MYF(MY_WME)))
goto err;
my_free(file_buffer, MYF(0));
DBUG_RETURN(0);
err:
my_free(file_buffer, MYF(0));
malloc_err:
my_fclose(cnf_file, MYF(0));
DBUG_RETURN(1); /* out of resources */
err_fopen:
DBUG_RETURN(-1); /* cannot access the option file */
}
/* /*
Process config files in default directories. Process config files in default directories.
......
...@@ -30,7 +30,9 @@ ...@@ -30,7 +30,9 @@
MyFlags Flags MyFlags Flags
DESCRIPTION DESCRIPTION
my_chsize() truncates file if shorter else fill with the filler character my_chsize() truncates file if shorter else fill with the filler character.
The function also changes the file pointer. Usually it points to the end
of the file after execution.
RETURN VALUE RETURN VALUE
0 Ok 0 Ok
......
...@@ -64,7 +64,7 @@ int Buffer::append(uint position, const char *string, uint len_arg) ...@@ -64,7 +64,7 @@ int Buffer::append(uint position, const char *string, uint len_arg)
DESCRIPTION DESCRIPTION
The method checks whether it is possible to pus a string of teh "len_arg" The method checks whether it is possible to put a string of the "len_arg"
length into the buffer, starting from "position" byte. In the case when the length into the buffer, starting from "position" byte. In the case when the
buffer is too small it reallocs the buffer. The total size of the buffer is buffer is too small it reallocs the buffer. The total size of the buffer is
restricted with 16 Mb. restricted with 16 Mb.
...@@ -81,7 +81,7 @@ int Buffer::reserve(uint position, uint len_arg) ...@@ -81,7 +81,7 @@ int Buffer::reserve(uint position, uint len_arg)
if (position + len_arg >= buffer_size) if (position + len_arg >= buffer_size)
{ {
buffer= (char *) my_realloc(buffer, buffer= (char*) my_realloc(buffer,
min(MAX_BUFFER_SIZE, min(MAX_BUFFER_SIZE,
max((uint) (buffer_size*1.5), max((uint) (buffer_size*1.5),
position + len_arg)), MYF(0)); position + len_arg)), MYF(0));
......
This diff is collapsed.
...@@ -31,7 +31,6 @@ public: ...@@ -31,7 +31,6 @@ public:
Show_instances(Instance_map *instance_map_arg): Command(instance_map_arg) Show_instances(Instance_map *instance_map_arg): Command(instance_map_arg)
{} {}
int do_command(struct st_net *net);
int execute(struct st_net *net, ulong connection_id); int execute(struct st_net *net, ulong connection_id);
}; };
...@@ -60,8 +59,8 @@ class Show_instance_status : public Command ...@@ -60,8 +59,8 @@ class Show_instance_status : public Command
{ {
public: public:
Show_instance_status(Instance_map *instance_map_arg, const char *name, uint len); Show_instance_status(Instance_map *instance_map_arg,
int do_command(struct st_net *net, const char *instance_name); const char *name, uint len);
int execute(struct st_net *net, ulong connection_id); int execute(struct st_net *net, ulong connection_id);
const char *instance_name; const char *instance_name;
}; };
...@@ -76,10 +75,10 @@ class Show_instance_options : public Command ...@@ -76,10 +75,10 @@ class Show_instance_options : public Command
{ {
public: public:
Show_instance_options(Instance_map *instance_map_arg, const char *name, uint len); Show_instance_options(Instance_map *instance_map_arg,
const char *name, uint len);
int execute(struct st_net *net, ulong connection_id); int execute(struct st_net *net, ulong connection_id);
int do_command(struct st_net *net, const char *instance_name);
const char *instance_name; const char *instance_name;
}; };
...@@ -129,7 +128,6 @@ public: ...@@ -129,7 +128,6 @@ public:
Show_instance_log(Instance_map *instance_map_arg, const char *name, Show_instance_log(Instance_map *instance_map_arg, const char *name,
uint len, Log_type log_type_arg, const char *size_arg, uint len, Log_type log_type_arg, const char *size_arg,
const char *offset_arg); const char *offset_arg);
int do_command(struct st_net *net, const char *instance_name);
int execute(struct st_net *net, ulong connection_id); int execute(struct st_net *net, ulong connection_id);
Log_type log_type; Log_type log_type;
const char *instance_name; const char *instance_name;
...@@ -147,8 +145,8 @@ class Show_instance_log_files : public Command ...@@ -147,8 +145,8 @@ class Show_instance_log_files : public Command
{ {
public: public:
Show_instance_log_files(Instance_map *instance_map_arg, const char *name, uint len); Show_instance_log_files(Instance_map *instance_map_arg,
int do_command(struct st_net *net, const char *instance_name); const char *name, uint len);
int execute(struct st_net *net, ulong connection_id); int execute(struct st_net *net, ulong connection_id);
const char *instance_name; const char *instance_name;
const char *option; const char *option;
...@@ -156,10 +154,10 @@ public: ...@@ -156,10 +154,10 @@ public:
/* /*
Syntax error command. This command is issued if parser reported a syntax error. Syntax error command. This command is issued if parser reported a syntax
We need it to distinguish the parse error and the situation when parser internal error. We need it to distinguish the parse error and the situation when
error occured. E.g. parsing failed because we hadn't had enought memory. In the parser internal error occured. E.g. parsing failed because we hadn't had
latter case parse_command() should return an error. enought memory. In the latter case parse_command() should return an error.
*/ */
class Syntax_error : public Command class Syntax_error : public Command
...@@ -185,7 +183,7 @@ public: ...@@ -185,7 +183,7 @@ public:
virtual int do_command(struct st_net *net); virtual int do_command(struct st_net *net);
int execute(struct st_net *net, ulong connection_id); int execute(struct st_net *net, ulong connection_id);
protected: protected:
int correct_file(bool skip); int correct_file(int skip);
public: public:
const char *instance_name; const char *instance_name;
uint instance_name_len; uint instance_name_len;
......
...@@ -315,7 +315,7 @@ int Guardian_thread::guard(Instance *instance, bool nolock) ...@@ -315,7 +315,7 @@ int Guardian_thread::guard(Instance *instance, bool nolock)
content->restart_counter= 0; content->restart_counter= 0;
content->crash_moment= 0; content->crash_moment= 0;
content->state= NOT_STARTED; content->state= NOT_STARTED;
node->data= (void *) content; node->data= (void*) content;
if (nolock) if (nolock)
guarded_instances= list_add(guarded_instances, node); guarded_instances= list_add(guarded_instances, node);
......
...@@ -304,12 +304,11 @@ void Instance::kill_instance(int signum) ...@@ -304,12 +304,11 @@ void Instance::kill_instance(int signum)
*/ */
if (!kill(pid, signum)) if (!kill(pid, signum))
options.unlink_pidfile(); options.unlink_pidfile();
else else if (signum == SIGKILL) /* really killed instance with SIGKILL */
if (signum == SIGKILL) /* really killed instance with SIGKILL */ log_error("The instance %s is being stopped forsibly. Normally \
log_error("The instance %s is being stopped forsibly. Normally \ it should not happed. Probably the instance has been \
it should not happed. Probably the instance has been \ hanging. You should also check your IM setup",
hanging. You should also check your IM setup", options.instance_name);
options.instance_name);
} }
return; return;
} }
......
...@@ -246,7 +246,7 @@ int Instance_map::load() ...@@ -246,7 +246,7 @@ int Instance_map::load()
argv_options[1]= '\0'; argv_options[1]= '\0';
if (my_search_option_files("my", &argc, (char ***) &argv, &args_used, if (my_search_option_files("my", &argc, (char ***) &argv, &args_used,
process_option, (void *) this) || process_option, (void*) this) ||
complete_initialization()) complete_initialization())
return 1; return 1;
......
...@@ -21,7 +21,6 @@ ...@@ -21,7 +21,6 @@
#include "instance_options.h" #include "instance_options.h"
#include "parse_output.h" #include "parse_output.h"
#include "parse.h"
#include "buffer.h" #include "buffer.h"
#include <my_sys.h> #include <my_sys.h>
...@@ -36,7 +35,7 @@ ...@@ -36,7 +35,7 @@
get_default_option() get_default_option()
result buffer to put found value result buffer to put found value
result_len buffer size result_len buffer size
oprion_name the name of the option, prefixed with "--" option_name the name of the option, prefixed with "--"
DESCRIPTION DESCRIPTION
...@@ -47,6 +46,7 @@ ...@@ -47,6 +46,7 @@
1 - error occured 1 - error occured
*/ */
int Instance_options::get_default_option(char *result, size_t result_len, int Instance_options::get_default_option(char *result, size_t result_len,
const char *option_name) const char *option_name)
{ {
...@@ -76,16 +76,30 @@ err: ...@@ -76,16 +76,30 @@ err:
} }
/*
Get compiled-in value of default_option
SYNOPSYS
get_default_option()
result buffer to put found value
result_len buffer size
option_name the name of the option, prefixed with "--"
DESCRIPTION
Get compile-in value of requested option from server
RETURN
0 - ok
1 - error occured
*/
int Instance_options::fill_log_options() int Instance_options::fill_log_options()
{ {
/* array for the log option for mysqld */
enum { MAX_LOG_OPTIONS= 8 };
enum { MAX_LOG_OPTION_LENGTH= 256 };
/* the last option must be '\0', so we reserve space for it */
char log_options[MAX_LOG_OPTIONS + 1][MAX_LOG_OPTION_LENGTH];
Buffer buff; Buffer buff;
uint position= 0; uint position= 0;
char **tmp_argv= argv; char **tmp_argv= argv;
enum { MAX_LOG_OPTION_LENGTH= 256 };
char datadir[MAX_LOG_OPTION_LENGTH]; char datadir[MAX_LOG_OPTION_LENGTH];
char hostname[MAX_LOG_OPTION_LENGTH]; char hostname[MAX_LOG_OPTION_LENGTH];
uint hostname_length; uint hostname_length;
...@@ -93,43 +107,17 @@ int Instance_options::fill_log_options() ...@@ -93,43 +107,17 @@ int Instance_options::fill_log_options()
{ {
const char *name; const char *name;
uint length; uint length;
const char **value; char **value;
const char *default_suffix; const char *default_suffix;
} logs[]= } logs_st[]=
{ {
{"--log-error", 11, &error_log, ".err"}, {"--log-error", 11, &(logs[LOG_ERROR]), ".err"},
{"--log", 5, &query_log, ".log"}, {"--log", 5, &(logs[LOG_GENERAL]), ".log"},
{"--log-slow-queries", 18, &slow_log, "-slow.log"}, {"--log-slow-queries", 18, &(logs[LOG_SLOW]), "-slow.log"},
{NULL, 0, NULL, NULL} {NULL, 0, NULL, NULL}
}; };
struct log_files_st *log_files; struct log_files_st *log_files;
/* clean the buffer before usage */
bzero(log_options, sizeof(log_options));
/* create a "mysqld <argv_options>" command in the buffer */
buff.append(position, mysqld_path, strlen(mysqld_path));
position= strlen(mysqld_path);
/* skip the first option */
tmp_argv++;
while (*tmp_argv != 0)
{
buff.append(position, " ", 1);
position++;
buff.append(position, *tmp_argv, strlen(*tmp_argv));
position+= strlen(*tmp_argv);
tmp_argv++;
}
buff.append(position, "\0", 1);
position++;
/* get options and parse them */
if (parse_arguments(buff.buffer, "--log", (char *) log_options,
MAX_LOG_OPTIONS + 1, MAX_LOG_OPTION_LENGTH))
goto err;
/* compute hostname and datadir for the instance */ /* compute hostname and datadir for the instance */
if (mysqld_datadir == NULL) if (mysqld_datadir == NULL)
{ {
...@@ -148,11 +136,11 @@ int Instance_options::fill_log_options() ...@@ -148,11 +136,11 @@ int Instance_options::fill_log_options()
hostname_length= strlen(hostname); hostname_length= strlen(hostname);
for (log_files= logs; log_files->name; log_files++) for (log_files= logs_st; log_files->name; log_files++)
{ {
for (int i=0; (i < MAX_LOG_OPTIONS) && (log_options[i][0] != '\0'); i++) for (int i=0; (argv[i] != 0); i++)
{ {
if (!strncmp(log_options[i], log_files->name, log_files->length)) if (!strncmp(argv[i], log_files->name, log_files->length))
{ {
/* /*
This is really log_files->name option if and only if it is followed This is really log_files->name option if and only if it is followed
...@@ -160,8 +148,8 @@ int Instance_options::fill_log_options() ...@@ -160,8 +148,8 @@ int Instance_options::fill_log_options()
options as '--log' and '--log-bin'. This is checked in the following options as '--log' and '--log-bin'. This is checked in the following
two statements. two statements.
*/ */
if (log_options[i][log_files->length] == '\0' || if (argv[i][log_files->length] == '\0' ||
my_isspace(default_charset_info, log_options[i][log_files->length])) my_isspace(default_charset_info, argv[i][log_files->length]))
{ {
char full_name[MAX_LOG_OPTION_LENGTH]; char full_name[MAX_LOG_OPTION_LENGTH];
...@@ -178,21 +166,25 @@ int Instance_options::fill_log_options() ...@@ -178,21 +166,25 @@ int Instance_options::fill_log_options()
else else
goto err; goto err;
*(log_files->value)= strdup_root(&alloc, datadir); /*
If there were specified two identical logfiles options,
we would loose some memory in MEM_ROOT here. However
this situation is not typical.
*/
*(log_files->value)= strdup_root(&alloc, full_name);
} }
if (log_options[i][log_files->length] == '=') if (argv[i][log_files->length] == '=')
{ {
char full_name[MAX_LOG_OPTION_LENGTH]; char full_name[MAX_LOG_OPTION_LENGTH];
fn_format(full_name, log_options[i] +log_files->length + 1, fn_format(full_name, argv[i] +log_files->length + 1,
datadir, "", MY_UNPACK_FILENAME | MY_SAFE_PATH); datadir, "", MY_UNPACK_FILENAME | MY_SAFE_PATH);
if (!(*(log_files->value)= if (!(*(log_files->value)=
strdup_root(&alloc, full_name))) strdup_root(&alloc, full_name)))
goto err; goto err;
} }
} }
} }
} }
...@@ -205,6 +197,25 @@ err: ...@@ -205,6 +197,25 @@ err:
} }
/*
Get the full pid file name with path
SYNOPSYS
get_pid_filaname()
result buffer to sotre the pidfile value
IMPLEMENTATION
Get the data directory, then get the pid filename
(which is always set for an instance), then load the
full path with my_load_path(). It takes into account
whether it is already an absolute path or it should be
prefixed with the datadir and so on.
RETURN
0 - ok
1 - error occured
*/
int 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;
...@@ -405,7 +416,7 @@ int Instance_options::add_to_argv(const char* option) ...@@ -405,7 +416,7 @@ int Instance_options::add_to_argv(const char* option)
DBUG_ASSERT(filled_default_options < MAX_NUMBER_OF_DEFAULT_OPTIONS); DBUG_ASSERT(filled_default_options < MAX_NUMBER_OF_DEFAULT_OPTIONS);
if ((option)) if ((option))
argv[filled_default_options++]= (char *) option; argv[filled_default_options++]= (char*) option;
return 0; return 0;
} }
...@@ -433,10 +444,10 @@ int Instance_options::init(const char *instance_name_arg) ...@@ -433,10 +444,10 @@ int Instance_options::init(const char *instance_name_arg)
init_alloc_root(&alloc, MEM_ROOT_BLOCK_SIZE, 0); init_alloc_root(&alloc, MEM_ROOT_BLOCK_SIZE, 0);
if (my_init_dynamic_array(&options_array, sizeof(char *), 0, 32)) if (my_init_dynamic_array(&options_array, sizeof(char*), 0, 32))
goto err; goto err;
if (!(instance_name= strmake_root(&alloc, (char *) instance_name_arg, if (!(instance_name= strmake_root(&alloc, (char*) instance_name_arg,
instance_name_len))) instance_name_len)))
goto err; goto err;
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include <my_global.h> #include <my_global.h>
#include <my_sys.h> #include <my_sys.h>
#include "parse.h"
#ifdef __GNUC__ #ifdef __GNUC__
#pragma interface #pragma interface
...@@ -40,8 +41,7 @@ public: ...@@ -40,8 +41,7 @@ public:
mysqld_socket(0), mysqld_datadir(0), mysqld_socket(0), mysqld_datadir(0),
mysqld_bind_address(0), mysqld_pid_file(0), mysqld_port(0), mysqld_bind_address(0), mysqld_pid_file(0), mysqld_port(0),
mysqld_port_val(0), mysqld_path(0), nonguarded(0), shutdown_delay(0), mysqld_port_val(0), mysqld_path(0), nonguarded(0), shutdown_delay(0),
shutdown_delay_val(0), error_log(0), query_log(0), slow_log(0), shutdown_delay_val(0), filled_default_options(0)
filled_default_options(0)
{} {}
~Instance_options(); ~Instance_options();
/* fills in argv */ /* fills in argv */
...@@ -77,9 +77,8 @@ public: ...@@ -77,9 +77,8 @@ public:
const char *nonguarded; const char *nonguarded;
const char *shutdown_delay; const char *shutdown_delay;
uint shutdown_delay_val; uint shutdown_delay_val;
const char *error_log; /* log enums are defined in parse.h */
const char *query_log; char *logs[3];
const char *slow_log;
/* this value is computed and cashed here */ /* this value is computed and cashed here */
DYNAMIC_ARRAY options_array; DYNAMIC_ARRAY options_array;
......
...@@ -241,23 +241,20 @@ void Listener_thread::run() ...@@ -241,23 +241,20 @@ void Listener_thread::run()
} }
} }
} }
else else if (FD_ISSET(ip_socket, &read_fds_arg))
if (FD_ISSET(ip_socket, &read_fds_arg)) {
int client_fd= accept(ip_socket, 0, 0);
/* accept may return -1 (failure or spurious wakeup) */
if (client_fd >= 0) // connection established
{ {
int client_fd= accept(ip_socket, 0, 0); if (Vio *vio= vio_new(client_fd, VIO_TYPE_TCPIP, 0))
/* accept may return -1 (failure or spurious wakeup) */ handle_new_mysql_connection(vio);
if (client_fd >= 0) // connection established else
{ {
if (Vio *vio= vio_new(client_fd, VIO_TYPE_TCPIP, 0)) shutdown(client_fd, SHUT_RDWR);
{ close(client_fd);
handle_new_mysql_connection(vio);
}
else
{
shutdown(client_fd, SHUT_RDWR);
close(client_fd);
}
} }
}
} }
} }
} }
......
...@@ -70,7 +70,7 @@ static inline void log(FILE *file, const char *format, va_list args) ...@@ -70,7 +70,7 @@ static inline void log(FILE *file, const char *format, va_list args)
if (n < 0 || n == sizeof(buff_stack)) if (n < 0 || n == sizeof(buff_stack))
{ {
int size= sizeof(buff_stack) * 2; int size= sizeof(buff_stack) * 2;
buff_msg= (char *) my_malloc(size, 0); buff_msg= (char*) my_malloc(size, MYF(0));
while (true) while (true)
{ {
if (buff_msg == 0) if (buff_msg == 0)
...@@ -86,16 +86,16 @@ static inline void log(FILE *file, const char *format, va_list args) ...@@ -86,16 +86,16 @@ static inline void log(FILE *file, const char *format, va_list args)
size*= 2; size*= 2;
/* realloc() does unnecessary memcpy */ /* realloc() does unnecessary memcpy */
my_free(buff_msg, 0); my_free(buff_msg, 0);
buff_msg= (char *) my_malloc(size, 0); buff_msg= (char*) my_malloc(size, MYF(0));
} }
} }
else if ((size_t) n > sizeof(buff_stack)) else if ((size_t) n > sizeof(buff_stack))
{ {
buff_msg= (char *) my_malloc(n + 1, 0); buff_msg= (char*) my_malloc(n + 1, MYF(0));
#ifdef DBUG #ifdef DBUG
DBUG_ASSERT(n == vsnprintf(buff_msg, n + 1, format, args)); DBUG_ASSERT(n == vsnprintf(buff_msg, n + 1, format, args));
#else #else
vsnprintf(buff_msg, n + 1, format, args); vsnprintf(buff_msg, n + 1, format, args);
#endif #endif
} }
fprintf(file, "%s%s\n", buff_date, buff_msg); fprintf(file, "%s%s\n", buff_date, buff_msg);
......
...@@ -197,8 +197,7 @@ void manager(const Options &options) ...@@ -197,8 +197,7 @@ void manager(const Options &options)
goto err; goto err;
} }
switch (signo) switch (signo) {
{
case THR_SERVER_ALARM: case THR_SERVER_ALARM:
process_alarm(signo); process_alarm(signo);
break; break;
......
...@@ -55,8 +55,12 @@ static const char *mysqld_error_message(unsigned sql_errno) ...@@ -55,8 +55,12 @@ static const char *mysqld_error_message(unsigned sql_errno)
case ER_CANNOT_START_INSTANCE: case ER_CANNOT_START_INSTANCE:
return "Cannot start instance. Possible reasons are wrong instance options" return "Cannot start instance. Possible reasons are wrong instance options"
" or resources shortage"; " or resources shortage";
case ER_OFFSET_ERROR:
return "Cannot read negative number of bytes";
case ER_STOP_INSTANCE: case ER_STOP_INSTANCE:
return "Cannot stop instance"; return "Cannot stop instance";
case ER_READ_FILE:
return "Cannot read requested part of the logfile";
case ER_NO_SUCH_LOG: case ER_NO_SUCH_LOG:
return "The instance has no such log enabled"; return "The instance has no such log enabled";
case ER_OPEN_LOGFILE: case ER_OPEN_LOGFILE:
......
...@@ -261,10 +261,10 @@ int Mysql_connection_thread::check_connection() ...@@ -261,10 +261,10 @@ int Mysql_connection_thread::check_connection()
} }
client_capabilities|= ((ulong) uint2korr(net.read_pos + 2)) << 16; client_capabilities|= ((ulong) uint2korr(net.read_pos + 2)) << 16;
pos= (char *) net.read_pos + 32; pos= (char*) net.read_pos + 32;
/* At least one byte for username and one byte for password */ /* At least one byte for username and one byte for password */
if (pos >= (char *) net.read_pos + pkt_len + 2) if (pos >= (char*) net.read_pos + pkt_len + 2)
{ {
/*TODO add user and password handling in error messages*/ /*TODO add user and password handling in error messages*/
net_send_error(&net, ER_HANDSHAKE_ERROR); net_send_error(&net, ER_HANDSHAKE_ERROR);
...@@ -301,9 +301,7 @@ int Mysql_connection_thread::do_command() ...@@ -301,9 +301,7 @@ int Mysql_connection_thread::do_command()
{ {
/* Check if we can continue without closing the connection */ /* Check if we can continue without closing the connection */
if (net.error != 3) // what is 3 - find out if (net.error != 3) // what is 3 - find out
{
return 1; return 1;
}
if (thread_registry.is_shutdown()) if (thread_registry.is_shutdown())
return 1; return 1;
net_send_error(&net, net.last_errno); net_send_error(&net, net.last_errno);
...@@ -346,14 +344,12 @@ int Mysql_connection_thread::dispatch_command(enum enum_server_command command, ...@@ -346,14 +344,12 @@ int Mysql_connection_thread::dispatch_command(enum enum_server_command command,
res= command->execute(&net, connection_id); res= command->execute(&net, connection_id);
delete command; delete command;
if (!res) if (!res)
{ log_info("query for connection %d executed ok",connection_id);
log_info("query for connection %d executed ok",connection_id);
}
else else
{ {
log_info("query for connection %d executed err=%d",connection_id,res); log_info("query for connection %d executed err=%d",connection_id,res);
net_send_error(&net, res); net_send_error(&net, res);
return 0; return 0;
} }
} }
else else
......
...@@ -27,5 +27,7 @@ ...@@ -27,5 +27,7 @@
#define ER_OPEN_LOGFILE 3006 #define ER_OPEN_LOGFILE 3006
#define ER_GUESS_LOGFILE 3007 #define ER_GUESS_LOGFILE 3007
#define ER_ACCESS_OPTION_FILE 3008 #define ER_ACCESS_OPTION_FILE 3008
#define ER_OFFSET_ERROR 3009
#define ER_READ_FILE 3010
#endif /* INCLUDES_MYSQL_INSTANCE_MANAGER_MYSQL_MANAGER_ERROR_H */ #endif /* INCLUDES_MYSQL_INSTANCE_MANAGER_MYSQL_MANAGER_ERROR_H */
...@@ -136,7 +136,8 @@ static struct passwd *check_user(const char *user) ...@@ -136,7 +136,8 @@ static struct passwd *check_user(const char *user)
{ {
/* Allow a numeric uid to be used */ /* Allow a numeric uid to be used */
const char *pos; const char *pos;
for (pos= user; my_isdigit(default_charset_info, *pos); pos++) ; for (pos= user; my_isdigit(default_charset_info, *pos); pos++)
{}
if (*pos) /* Not numeric id */ if (*pos) /* Not numeric id */
goto err; goto err;
if (!(user_info= getpwuid(atoi(user)))) if (!(user_info= getpwuid(atoi(user))))
......
...@@ -158,7 +158,7 @@ static void passwd() ...@@ -158,7 +158,7 @@ static void passwd()
fprintf(stderr, "Creating record for new user.\n"); fprintf(stderr, "Creating record for new user.\n");
fprintf(stderr, "Enter user name: "); fprintf(stderr, "Enter user name: ");
if (! fgets(user, sizeof(user), stdin)) if (!fgets(user, sizeof(user), stdin))
{ {
fprintf(stderr, "Unable to read user.\n"); fprintf(stderr, "Unable to read user.\n");
return; return;
......
...@@ -198,9 +198,7 @@ Command *parse_command(Command_factory *factory, const char *text) ...@@ -198,9 +198,7 @@ Command *parse_command(Command_factory *factory, const char *text)
/* should be empty */ /* should be empty */
get_word(&text, &word_len); get_word(&text, &word_len);
if (word_len) if (word_len)
{
goto syntax_error; goto syntax_error;
}
if (skip) if (skip)
command= factory->new_Unset_option(instance_name, instance_name_len, command= factory->new_Unset_option(instance_name, instance_name_len,
...@@ -330,44 +328,3 @@ syntax_error: ...@@ -330,44 +328,3 @@ syntax_error:
} }
return command; return command;
} }
/* additional parse function, needed to parse */
/* create an array of strings from the output, starting from "word" */
int parse_arguments(const char *command, const char *word, char *result,
int max_result_cardinality, size_t option_len)
{
int wordlen;
int i= 0; /* result array index */
/* should be enough to store the string from the output */
enum { MAX_LINE_LEN= 4096 };
char linebuf[MAX_LINE_LEN];
wordlen= strlen(word);
uint lineword_len= 0;
const char *linep= command;
get_word((const char **) &linep, &lineword_len, NONSPACE);
while ((*linep != '\0') && (i < max_result_cardinality))
{
if (!strncmp(word, linep, wordlen))
{
strncpy(result + i*option_len, linep, lineword_len);
*(result + i*option_len + lineword_len)= '\0';
linep+= lineword_len;
i++;
}
else
linep+= lineword_len;
get_word((const char **) &linep, &lineword_len, NONSPACE);
/* stop if we've filled the array */
if (i >= max_result_cardinality)
break;
}
return 0;
}
...@@ -31,9 +31,6 @@ enum Log_type ...@@ -31,9 +31,6 @@ enum Log_type
Command *parse_command(Command_factory *factory, const char *text); Command *parse_command(Command_factory *factory, const char *text);
int parse_arguments(const char *command, const char *word, char *result,
int max_result_cardinality, size_t option_len);
/* define kinds of the word seek method */ /* define kinds of the word seek method */
enum { ALPHANUM= 1, NONSPACE }; enum { ALPHANUM= 1, NONSPACE };
......
...@@ -122,6 +122,7 @@ int store_to_string(Buffer *buf, const char *string, uint *position, ...@@ -122,6 +122,7 @@ int store_to_string(Buffer *buf, const char *string, uint *position,
{ {
uint currpos; uint currpos;
/* reserve max amount of bytes needed to store length */
if (buf->reserve(*position, 9)) if (buf->reserve(*position, 9))
goto err; goto err;
currpos= (net_store_length(buf->buffer + *position, currpos= (net_store_length(buf->buffer + *position,
...@@ -175,10 +176,10 @@ int send_fields(struct st_net *net, LIST *fields) ...@@ -175,10 +176,10 @@ int send_fields(struct st_net *net, LIST *fields)
position= 0; position= 0;
field= (NAME_WITH_LENGTH *) tmp->data; field= (NAME_WITH_LENGTH *) tmp->data;
store_to_string(&send_buff, (char *) "", &position); /* catalog name */ store_to_string(&send_buff, (char*) "", &position); /* catalog name */
store_to_string(&send_buff, (char *) "", &position); /* db name */ store_to_string(&send_buff, (char*) "", &position); /* db name */
store_to_string(&send_buff, (char *) "", &position); /* table name */ store_to_string(&send_buff, (char*) "", &position); /* table name */
store_to_string(&send_buff, (char *) "", &position); /* table name alias */ store_to_string(&send_buff, (char*) "", &position); /* table name alias */
store_to_string(&send_buff, field->name, &position); /* column name */ store_to_string(&send_buff, field->name, &position); /* column name */
store_to_string(&send_buff, field->name, &position); /* column name alias */ store_to_string(&send_buff, field->name, &position); /* column name alias */
send_buff.reserve(position, 12); send_buff.reserve(position, 12);
......
...@@ -25,6 +25,9 @@ typedef struct field { ...@@ -25,6 +25,9 @@ typedef struct field {
uint length; uint length;
} NAME_WITH_LENGTH; } NAME_WITH_LENGTH;
/* default field length to be used in various field-realted functions */
enum { DEFAULT_FIELD_LENGTH= 20 };
struct st_net; struct st_net;
int net_send_ok(struct st_net *net, unsigned long connection_id, int net_send_ok(struct st_net *net, unsigned long connection_id,
......
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