mirror of
https://github.com/MariaDB/server.git
synced 2025-01-17 04:22:27 +01:00
various fixes
server-tools/instance-manager/buffer.cc: use my_realloc instead of realloc server-tools/instance-manager/buffer.h: use my_malloc instead of malloc server-tools/instance-manager/commands.cc: No need to send a buffer if there were some error while writing to it server-tools/instance-manager/instance_options.cc: cleanup server-tools/instance-manager/manager.cc: check sigwait return value server-tools/instance-manager/parse_output.cc: fixed a bug, found with valgrind
This commit is contained in:
parent
dce2554f91
commit
5bd607785a
6 changed files with 38 additions and 21 deletions
|
@ -81,10 +81,10 @@ int Buffer::reserve(uint position, uint len_arg)
|
||||||
|
|
||||||
if (position + len_arg>= buffer_size)
|
if (position + len_arg>= buffer_size)
|
||||||
{
|
{
|
||||||
buffer= (char *) 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)));
|
position + len_arg)), MYF(0));
|
||||||
if (buffer == NULL)
|
if (buffer == NULL)
|
||||||
goto err;
|
goto err;
|
||||||
buffer_size= (uint) (buffer_size*1.5);
|
buffer_size= (uint) (buffer_size*1.5);
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
||||||
|
|
||||||
#include <my_global.h>
|
#include <my_global.h>
|
||||||
|
#include <my_sys.h>
|
||||||
|
|
||||||
#ifdef __GNUC__
|
#ifdef __GNUC__
|
||||||
#pragma interface
|
#pragma interface
|
||||||
|
@ -45,7 +46,7 @@ public:
|
||||||
/*
|
/*
|
||||||
As append() will invokes realloc() anyway, it's ok if malloc returns 0
|
As append() will invokes realloc() anyway, it's ok if malloc returns 0
|
||||||
*/
|
*/
|
||||||
if (!(buffer= (char*) malloc(buffer_size)))
|
if (!(buffer= (char*) my_malloc(buffer_size, MYF(0))))
|
||||||
buffer_size= 0;
|
buffer_size= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -184,8 +184,8 @@ int Show_instance_status::do_command(struct st_net *net,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (my_net_write(net, send_buff.buffer, (uint) position) ||
|
if (send_buff.is_error() ||
|
||||||
send_buff.is_error())
|
my_net_write(net, send_buff.buffer, (uint) position))
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -271,8 +271,8 @@ int Show_instance_options::do_command(struct st_net *net,
|
||||||
store_to_string(&send_buff,
|
store_to_string(&send_buff,
|
||||||
(char *) instance->options.mysqld_path,
|
(char *) instance->options.mysqld_path,
|
||||||
&position);
|
&position);
|
||||||
if (my_net_write(net, send_buff.buffer, (uint) position) ||
|
if (send_buff.is_error() ||
|
||||||
send_buff.is_error())
|
my_net_write(net, send_buff.buffer, (uint) position))
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -281,8 +281,8 @@ int Show_instance_options::do_command(struct st_net *net,
|
||||||
position= 0;
|
position= 0;
|
||||||
store_to_string(&send_buff, (char *) "nonguarded", &position);
|
store_to_string(&send_buff, (char *) "nonguarded", &position);
|
||||||
store_to_string(&send_buff, "", &position);
|
store_to_string(&send_buff, "", &position);
|
||||||
if (my_net_write(net, send_buff.buffer, (uint) position) ||
|
if (send_buff.is_error() ||
|
||||||
send_buff.is_error())
|
my_net_write(net, send_buff.buffer, (uint) position))
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -299,8 +299,8 @@ int Show_instance_options::do_command(struct st_net *net,
|
||||||
store_to_string(&send_buff, option_value + 1, &position);
|
store_to_string(&send_buff, option_value + 1, &position);
|
||||||
/* join name and the value into the same option again */
|
/* join name and the value into the same option again */
|
||||||
*option_value= '=';
|
*option_value= '=';
|
||||||
if (my_net_write(net, send_buff.buffer, (uint) position) ||
|
if (send_buff.is_error() ||
|
||||||
send_buff.is_error())
|
my_net_write(net, send_buff.buffer, (uint) position))
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,9 +80,7 @@ void Instance_options::get_pid_filename(char *result)
|
||||||
char datadir[MAX_PATH_LEN];
|
char datadir[MAX_PATH_LEN];
|
||||||
|
|
||||||
if (mysqld_datadir == NULL)
|
if (mysqld_datadir == NULL)
|
||||||
{
|
|
||||||
get_default_option(datadir, sizeof(datadir), "--datadir");
|
get_default_option(datadir, sizeof(datadir), "--datadir");
|
||||||
}
|
|
||||||
else
|
else
|
||||||
strxnmov(datadir, MAX_PATH_LEN - 1, strchr(mysqld_datadir, '=') + 1,
|
strxnmov(datadir, MAX_PATH_LEN - 1, strchr(mysqld_datadir, '=') + 1,
|
||||||
"/", NullS);
|
"/", NullS);
|
||||||
|
@ -106,8 +104,8 @@ pid_t Instance_options::get_pid()
|
||||||
FILE *pid_file_stream;
|
FILE *pid_file_stream;
|
||||||
|
|
||||||
/* get the pid */
|
/* get the pid */
|
||||||
if (pid_file_stream= my_fopen(pid_file_with_path,
|
if ((pid_file_stream= my_fopen(pid_file_with_path,
|
||||||
O_RDONLY | O_BINARY, MYF(0)))
|
O_RDONLY | O_BINARY, MYF(0))) != NULL)
|
||||||
{
|
{
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
|
|
||||||
|
|
|
@ -171,7 +171,14 @@ void manager(const Options &options)
|
||||||
|
|
||||||
while (!shutdown_complete)
|
while (!shutdown_complete)
|
||||||
{
|
{
|
||||||
sigwait(&mask, &signo);
|
int status= 0;
|
||||||
|
|
||||||
|
if (status= my_sigwait(&mask, &signo))
|
||||||
|
{
|
||||||
|
log_error("sigwait() failed");
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
|
||||||
switch (signo)
|
switch (signo)
|
||||||
{
|
{
|
||||||
case THR_SERVER_ALARM:
|
case THR_SERVER_ALARM:
|
||||||
|
|
|
@ -36,6 +36,10 @@
|
||||||
DESCRIPTION
|
DESCRIPTION
|
||||||
|
|
||||||
Parse output of the "command". Find the "word" and return the next one
|
Parse output of the "command". Find the "word" and return the next one
|
||||||
|
|
||||||
|
RETURN
|
||||||
|
0 - ok
|
||||||
|
1 - error occured
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int parse_output_and_get_value(const char *command, const char *word,
|
int parse_output_and_get_value(const char *command, const char *word,
|
||||||
|
@ -49,7 +53,8 @@ int parse_output_and_get_value(const char *command, const char *word,
|
||||||
|
|
||||||
wordlen= strlen(word);
|
wordlen= strlen(word);
|
||||||
|
|
||||||
output= popen(command, "r");
|
if ((output= popen(command, "r")) == NULL)
|
||||||
|
goto err;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
We want fully buffered stream. We also want system to
|
We want fully buffered stream. We also want system to
|
||||||
|
@ -69,15 +74,18 @@ int parse_output_and_get_value(const char *command, const char *word,
|
||||||
these are '/', '-' and '.' in the path expressions and filenames)
|
these are '/', '-' and '.' in the path expressions and filenames)
|
||||||
*/
|
*/
|
||||||
get_word((const char **) &linep, &lineword_len, NONSPACE);
|
get_word((const char **) &linep, &lineword_len, NONSPACE);
|
||||||
if (!strncmp(word, linep, wordlen) && *result != '\0')
|
if (!strncmp(word, linep, wordlen))
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
If we have found the word, return the next one. This is usually
|
If we have found the word, return the next one. This is usually
|
||||||
an option value.
|
an option value.
|
||||||
*/
|
*/
|
||||||
|
linep+= lineword_len; /* swallow the previous one */
|
||||||
get_word((const char **) &linep, &lineword_len, NONSPACE);
|
get_word((const char **) &linep, &lineword_len, NONSPACE);
|
||||||
DBUG_ASSERT(result_len > lineword_len);
|
if (result_len <= lineword_len)
|
||||||
|
goto err;
|
||||||
strncpy(result, linep, lineword_len);
|
strncpy(result, linep, lineword_len);
|
||||||
|
result[lineword_len]= '\0';
|
||||||
goto pclose;
|
goto pclose;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -87,4 +95,7 @@ pclose:
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
err:
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue