Commit 3e042c6d authored by anozdrin/alik@booka's avatar anozdrin/alik@booka

Polishing:

  - change some return types from int to bool;
  - add [ERROR] tag to log_error() output;
  - add [INFO] tag to log_info() output;
  - change log messages to be more consistent.
parent ff0325f1
......@@ -54,24 +54,24 @@ int HandleServiceOptions()
if (Options::Service::install_as_service)
{
if (winService.IsInstalled())
log_info("Service is already installed");
log_info("Service is already installed.");
else if (winService.Install())
log_info("Service installed successfully");
log_info("Service installed successfully.");
else
{
log_info("Service failed to install");
log_error("Service failed to install.");
ret_val= 1;
}
}
else if (Options::Service::remove_service)
{
if (! winService.IsInstalled())
log_info("Service is not installed");
log_info("Service is not installed.");
else if (winService.Remove())
log_info("Service removed successfully");
log_info("Service removed successfully.");
else
{
log_info("Service failed to remove");
log_error("Service failed to remove.");
ret_val= 1;
}
}
......@@ -81,7 +81,7 @@ int HandleServiceOptions()
if (!winService.Init())
{
log_info("Service failed to initialize.");
log_error("Service failed to initialize.");
fprintf(stderr,
"The service should be started by Windows Service Manager.\n"
"The MySQL Manager should be started with '--standalone'\n"
......
......@@ -1539,7 +1539,7 @@ int Set_option::process_option(Instance *instance, Named_value *option)
if (instance->is_mysqld_compatible() &&
Instance_options::is_option_im_specific(option->get_name()))
{
log_error("Error: IM-option (%s) can not be used "
log_error("IM-option (%s) can not be used "
"in the configuration of mysqld-compatible instance (%s).",
(const char *) option->get_name(),
(const char *) instance->get_name()->str);
......
......@@ -37,6 +37,10 @@
class Show_instances: public Command
{
public:
Show_instances()
{ }
public:
int execute(st_net *net, ulong connection_id);
......@@ -53,6 +57,10 @@ private:
class Flush_instances: public Command
{
public:
Flush_instances()
{ }
public:
int execute(st_net *net, ulong connection_id);
};
......@@ -311,6 +319,10 @@ private:
class Set_option: public Abstract_option_cmd
{
public:
Set_option()
{ }
protected:
virtual bool parse_args(const char **text);
virtual int process_option(Instance *instance, Named_value *option);
......@@ -324,6 +336,10 @@ protected:
class Unset_option: public Abstract_option_cmd
{
public:
Unset_option()
{ }
protected:
virtual bool parse_args(const char **text);
virtual int process_option(Instance *instance, Named_value *option);
......@@ -341,6 +357,10 @@ protected:
class Syntax_error: public Command
{
public:
Syntax_error()
{ }
public:
int execute(st_net *net, ulong connection_id);
};
......
......@@ -170,7 +170,7 @@ static bool start_process(Instance_options *instance_options,
/* exec never returns */
exit(1);
case -1:
log_info("Instance '%s': can not start mysqld: fork() failed.",
log_error("Instance '%s': can not start mysqld: fork() failed.",
(const char *) instance_options->instance_name.str);
return TRUE;
}
......@@ -699,10 +699,9 @@ void Instance::kill_mysqld(int signum)
/* Kill suceeded */
if (signum == SIGKILL) /* really killed instance with SIGKILL */
{
log_error("The instance '%s' is being stopped forcibly. Normally"
"it should not happen. Probably the instance has been"
"hanging. You should also check your IM setup",
log_error("Instance '%s': killed.",
(const char *) options.instance_name.str);
/* After sucessful hard kill the pidfile need to be removed */
options.unlink_pidfile();
}
......
......@@ -336,14 +336,14 @@ int Instance_map::create_instance(const LEX_STRING *instance_name,
if (!instance)
{
log_error("Error: can not allocate instance (name: '%s').",
log_error("Can not allocate instance (name: '%s').",
(const char *) instance_name->str);
return ER_OUT_OF_RESOURCES;
}
if (instance->init(instance_name))
{
log_error("Error: can not initialize instance (name: '%s').",
log_error("Can not initialize instance (name: '%s').",
(const char *) instance_name->str);
delete instance;
return ER_OUT_OF_RESOURCES;
......@@ -356,7 +356,7 @@ int Instance_map::create_instance(const LEX_STRING *instance_name,
if (instance->is_mysqld_compatible() &&
Instance_options::is_option_im_specific(option.get_name()))
{
log_error("Error: IM-option (%s) can not be used "
log_error("IM-option (%s) can not be used "
"in configuration of mysqld-compatible instance (%s).",
(const char *) option.get_name(),
(const char *) instance_name->str);
......@@ -373,7 +373,7 @@ int Instance_map::create_instance(const LEX_STRING *instance_name,
if (instance->complete_initialization())
{
log_error("Error: can not complete initialization of instance (name: '%s').",
log_error("Can not complete initialization of instance (name: '%s').",
(const char *) instance_name->str);
delete instance;
return ER_OUT_OF_RESOURCES;
......@@ -382,7 +382,7 @@ int Instance_map::create_instance(const LEX_STRING *instance_name,
if (add_instance(instance))
{
log_error("Error: can not register instance (name: '%s').",
log_error("Can not register instance (name: '%s').",
(const char *) instance_name->str);
delete instance;
return ER_OUT_OF_RESOURCES;
......@@ -426,7 +426,7 @@ bool Instance_map::complete_initialization()
if (create_instance(&Instance::DFLT_INSTANCE_NAME, NULL))
{
log_error("Error: could not create default instance.");
log_error("Can not create default instance.");
return TRUE;
}
......@@ -441,7 +441,7 @@ bool Instance_map::complete_initialization()
break;
default:
log_error("Error: could not add default instance to the config file.");
log_error("Can not add default instance to the config file.");
Instance *instance= find(&Instance::DFLT_INSTANCE_NAME);
......@@ -499,7 +499,7 @@ int Instance_map::load()
if (my_search_option_files(Options::Main::config_file, &argc,
(char ***) &argv, &args_used,
process_option, (void*) this))
log_info("Falling back to compiled-in defaults");
log_info("Falling back to compiled-in defaults.");
return complete_initialization();
}
......@@ -566,7 +566,7 @@ int create_instance_in_file(const LEX_STRING *instance_name,
if (my_access(Options::Main::config_file, W_OK))
{
log_error("Error: configuration file (%s) does not exist.",
log_error("Configuration file (%s) does not exist.",
(const char *) Options::Main::config_file);
return ER_CONF_FILE_DOES_NOT_EXIST;
}
......@@ -575,7 +575,7 @@ int create_instance_in_file(const LEX_STRING *instance_name,
if (cnf_file <= 0)
{
log_error("Error: can not open configuration file (%s): %s.",
log_error("Can not open configuration file (%s): %s.",
(const char *) Options::Main::config_file,
(const char *) strerror(errno));
return ER_ACCESS_OPTION_FILE;
......@@ -588,7 +588,7 @@ int create_instance_in_file(const LEX_STRING *instance_name,
my_write(cnf_file, (byte*)"]", 1, MYF(MY_NABP)) ||
my_write(cnf_file, (byte*)NEWLINE, NEWLINE_LEN, MYF(MY_NABP)))
{
log_error("Error: can not write to configuration file (%s): %s.",
log_error("Can not write to configuration file (%s): %s.",
(const char *) Options::Main::config_file,
(const char *) strerror(errno));
my_close(cnf_file, MYF(0));
......@@ -612,7 +612,7 @@ int create_instance_in_file(const LEX_STRING *instance_name,
if (my_write(cnf_file, (byte*)option_str, option_str_len, MYF(MY_NABP)) ||
my_write(cnf_file, (byte*)NEWLINE, NEWLINE_LEN, MYF(MY_NABP)))
{
log_error("Error: can not write to configuration file (%s): %s.",
log_error("Can not write to configuration file (%s): %s.",
(const char *) Options::Main::config_file,
(const char *) strerror(errno));
my_close(cnf_file, MYF(0));
......
......@@ -36,7 +36,7 @@
/* Create "mysqld ..." command in the buffer */
static inline int create_mysqld_command(Buffer *buf,
static inline bool create_mysqld_command(Buffer *buf,
const LEX_STRING *mysqld_path,
const LEX_STRING *option)
{
......@@ -55,9 +55,9 @@ static inline int create_mysqld_command(Buffer *buf,
/* here the '\0' character is copied from the option string */
buf->append(position, option->str, option->length + 1);
return buf->is_error();
return buf->is_error() ? TRUE : FALSE;
}
return 1;
return TRUE;
}
......@@ -152,27 +152,36 @@ err:
Get mysqld version string from "mysqld --version" output.
RETURN
0 - ok
1 - error occured
FALSE - ok
TRUE - error occured
*/
int Instance_options::fill_instance_version()
bool Instance_options::fill_instance_version()
{
char result[MAX_VERSION_LENGTH];
LEX_STRING version_option=
{ C_STRING_WITH_LEN(" --no-defaults --version") };
int rc= 1;
Buffer cmd(mysqld_path.length + version_option.length + 1);
if (create_mysqld_command(&cmd, &mysqld_path, &version_option))
goto err;
{
log_error("Failed to get version of '%s': out of memory.",
(const char *) mysqld_path.str);
return TRUE;
}
bzero(result, MAX_VERSION_LENGTH);
rc= parse_output_and_get_value(cmd.buffer, "Ver", result,
MAX_VERSION_LENGTH, GET_LINE);
if (parse_output_and_get_value(cmd.buffer, "Ver", result,
MAX_VERSION_LENGTH, GET_LINE))
{
log_error("Failed to get version of '%s': unexpected output.",
(const char *) mysqld_path.str);
return TRUE;
}
DBUG_ASSERT(*result != '\0');
if (*result != '\0')
{
char *start;
/* chop the newline from the end of the version string */
......@@ -184,11 +193,8 @@ int Instance_options::fill_instance_version()
mysqld_version= strdup_root(&alloc, start);
}
err:
if (rc)
log_error("fill_instance_version: Failed to get version of '%s'",
(const char *) mysqld_path.str);
return rc;
return FALSE;
}
......@@ -207,28 +213,37 @@ err:
script(for example libtool) or a symlink.
RETURN
0 - ok
1 - error occured
FALSE - ok
TRUE - error occured
*/
int Instance_options::fill_mysqld_real_path()
bool Instance_options::fill_mysqld_real_path()
{
char result[FN_REFLEN];
LEX_STRING help_option=
{ C_STRING_WITH_LEN(" --no-defaults --help") };
int rc= 1;
Buffer cmd(mysqld_path.length + help_option.length);
if (create_mysqld_command(&cmd, &mysqld_path, &help_option))
goto err;
{
log_error("Failed to get real path of '%s': out of memory.",
(const char *) mysqld_path.str);
return TRUE;
}
bzero(result, FN_REFLEN);
rc= parse_output_and_get_value(cmd.buffer, "Usage: ",
if (parse_output_and_get_value(cmd.buffer, "Usage: ",
result, FN_REFLEN,
GET_LINE);
GET_LINE))
{
log_error("Failed to get real path of '%s': unexpected output.",
(const char *) mysqld_path.str);
return TRUE;
}
DBUG_ASSERT(*result != '\0');
if (*result != '\0')
{
char* options_str;
/* chop the path of at [OPTIONS] */
......@@ -237,10 +252,8 @@ int Instance_options::fill_mysqld_real_path()
mysqld_real_path.str= strdup_root(&alloc, result);
mysqld_real_path.length= strlen(mysqld_real_path.str);
}
err:
if (rc)
log_error("fill_mysqld_real_path: Failed to get real path of mysqld");
return rc;
return FALSE;
}
......@@ -257,11 +270,11 @@ err:
file name and placement.
RETURN
0 - ok
1 - error occured
FALSE - ok
TRUE - error occured
*/
int Instance_options::fill_log_options()
bool Instance_options::fill_log_options()
{
Buffer buff;
enum { MAX_LOG_OPTION_LENGTH= 256 };
......@@ -287,7 +300,7 @@ int Instance_options::fill_log_options()
if (mysqld_datadir == NULL)
{
if (get_default_option(datadir, MAX_LOG_OPTION_LENGTH, "--datadir"))
goto err;
return TRUE;
}
else
{
......@@ -325,7 +338,7 @@ int Instance_options::fill_log_options()
if ((MAX_LOG_OPTION_LENGTH - strlen(full_name)) <=
strlen(log_files->default_suffix))
goto err;
return TRUE;
strmov(full_name + strlen(full_name), log_files->default_suffix);
......@@ -345,15 +358,13 @@ int Instance_options::fill_log_options()
datadir, "", MY_UNPACK_FILENAME | MY_SAFE_PATH);
if (!(*(log_files->value)= strdup_root(&alloc, full_name)))
goto err;
return TRUE;
}
}
}
}
return 0;
err:
return 1;
return FALSE;
}
......
......@@ -91,9 +91,9 @@ public:
char *logs[3];
private:
int fill_log_options();
int fill_instance_version();
int fill_mysqld_real_path();
bool fill_log_options();
bool fill_instance_version();
bool fill_mysqld_real_path();
int add_to_argv(const char *option);
int get_default_option(char *result, size_t result_len,
const char *option_name);
......
......@@ -127,8 +127,8 @@ void Listener::run()
if (rc == 0 || rc == -1)
{
if (rc == -1 && errno != EINTR)
log_error("Listener: select() failed, %s",
strerror(errno));
log_error("Listener: select() failed: %s.",
(const char *) strerror(errno));
continue;
}
......@@ -195,8 +195,8 @@ int Listener::create_tcp_socket()
int ip_socket= socket(AF_INET, SOCK_STREAM, 0);
if (ip_socket == INVALID_SOCKET)
{
log_error("Listener_thead: socket(AF_INET) failed, %s",
strerror(errno));
log_error("Listener: socket(AF_INET) failed: %s.",
(const char *) strerror(errno));
return -1;
}
......@@ -226,16 +226,16 @@ int Listener::create_tcp_socket()
if (bind(ip_socket, (struct sockaddr *) &ip_socket_address,
sizeof(ip_socket_address)))
{
log_error("Listener: bind(ip socket) failed, '%s'",
strerror(errno));
log_error("Listener: bind(ip socket) failed: %s.",
(const char *) strerror(errno));
close(ip_socket);
return -1;
}
if (listen(ip_socket, LISTEN_BACK_LOG_SIZE))
{
log_error("Listener: listen(ip socket) failed, %s",
strerror(errno));
log_error("Listener: listen(ip socket) failed: %s.",
(const char *) strerror(errno));
close(ip_socket);
return -1;
}
......@@ -248,7 +248,8 @@ int Listener::create_tcp_socket()
FD_SET(ip_socket, &read_fds);
sockets[num_sockets++]= ip_socket;
log_info("accepting connections on ip socket (port: %d)", (int) im_port);
log_info("Listener: accepting connections on ip socket (port: %d)...",
(int) im_port);
return 0;
}
......@@ -259,8 +260,8 @@ create_unix_socket(struct sockaddr_un &unix_socket_address)
int unix_socket= socket(AF_UNIX, SOCK_STREAM, 0);
if (unix_socket == INVALID_SOCKET)
{
log_error("Listener_thead: socket(AF_UNIX) failed, %s",
strerror(errno));
log_error("Listener: socket(AF_UNIX) failed: %s.",
(const char *) strerror(errno));
return -1;
}
......@@ -279,9 +280,9 @@ create_unix_socket(struct sockaddr_un &unix_socket_address)
if (bind(unix_socket, (struct sockaddr *) &unix_socket_address,
sizeof(unix_socket_address)))
{
log_error("Listener: bind(unix socket) failed, "
"socket file name is '%s', error '%s'",
unix_socket_address.sun_path, strerror(errno));
log_error("Listener: bind(unix socket) failed for '%s': %s.",
(const char *) unix_socket_address.sun_path,
(const char *) strerror(errno));
close(unix_socket);
return -1;
}
......@@ -290,8 +291,8 @@ create_unix_socket(struct sockaddr_un &unix_socket_address)
if (listen(unix_socket, LISTEN_BACK_LOG_SIZE))
{
log_error("Listener: listen(unix socket) failed, %s",
strerror(errno));
log_error("Listener: listen(unix socket) failed: %s.",
(const char *) strerror(errno));
close(unix_socket);
return -1;
}
......@@ -302,8 +303,8 @@ create_unix_socket(struct sockaddr_un &unix_socket_address)
/* make sure that instances won't be listening our sockets */
set_no_inherit(unix_socket);
log_info("accepting connections on unix socket '%s'",
unix_socket_address.sun_path);
log_info("Listener: accepting connections on unix socket '%s'...",
(const char *) unix_socket_address.sun_path);
sockets[num_sockets++]= unix_socket;
FD_SET(unix_socket, &read_fds);
return 0;
......@@ -325,7 +326,7 @@ void Listener::handle_new_mysql_connection(struct st_vio *vio)
vio, ++total_connection_count);
if (mysql_connection == NULL || mysql_connection->start(Thread::DETACHED))
{
log_error("handle_one_mysql_connection() failed");
log_error("Listener: can not start connection handler.");
delete mysql_connection;
vio_delete(vio);
}
......
......@@ -37,7 +37,8 @@
log()
*/
static inline void log(FILE *file, const char *format, va_list args)
static void log(FILE *file,const char *level_tag, const char *format,
va_list args)
{
/*
log() should be thread-safe; it implies that we either call fprintf()
......@@ -53,15 +54,16 @@ static inline void log(FILE *file, const char *format, va_list args)
localtime_r(&now, &bd_time);
char buff_date[128];
sprintf(buff_date, "[%d/%lu] [%02d/%02d/%02d %02d:%02d:%02d] ",
sprintf(buff_date, "[%d/%lu] [%02d/%02d/%02d %02d:%02d:%02d] [%s] ",
(int) getpid(),
(unsigned long) pthread_self(),
bd_time.tm_year % 100,
bd_time.tm_mon + 1,
bd_time.tm_mday,
bd_time.tm_hour,
bd_time.tm_min,
bd_time.tm_sec);
(int) bd_time.tm_year % 100,
(int) bd_time.tm_mon + 1,
(int) bd_time.tm_mday,
(int) bd_time.tm_hour,
(int) bd_time.tm_min,
(int) bd_time.tm_sec,
(const char *) level_tag);
/* Format the message */
char buff_stack[256];
......@@ -109,57 +111,73 @@ static inline void log(FILE *file, const char *format, va_list args)
/* don't fflush() the file: buffering strategy is set in log_init() */
}
/**************************************************************************
Logging: implementation of public interface.
**************************************************************************/
void log_error(const char *format, ...)
{
va_list args;
va_start(args, format);
log(stderr, format, args);
va_end(args);
}
/*
The function initializes logging sub-system.
SYNOPSIS
log_init()
*/
void log_info(const char *format, ...)
void log_init()
{
va_list args;
va_start(args, format);
log(stdout, format, args);
va_end(args);
/*
stderr is unbuffered by default; there is no good of line buffering,
as all logging is performed linewise - so remove buffering from stdout
also
*/
setbuf(stdout, 0);
}
/* TODO: rewrite with buffering print */
void print_info(const char *format, ...)
/*
The function is intended to log error messages. It precedes a message
with date, time and [ERROR] tag and print it to the stderr.
SYNOPSIS
log_error()
format [IN] format string
... [IN] arguments to format
*/
void log_error(const char *format, ...)
{
va_list args;
va_start(args, format);
vfprintf(stdout, format, args);
log(stderr, "ERROR", format, args);
va_end(args);
}
void print_error(const char *format, ...)
/*
The function is intended to log information messages. It precedes
a message with date, time and [INFO] tag and print it to the stdout.
SYNOPSIS
log_error()
format [IN] format string
... [IN] arguments to format
*/
void log_info(const char *format, ...)
{
va_list args;
va_start(args, format);
vfprintf(stderr, format, args);
log(stdout, "INFO", format, args);
va_end(args);
}
/*
log_init()
RETURN VALUE
0 ok
!0 error
*/
The function prints information to the error log and eixt(1).
void log_init()
{
/*
stderr is unbuffered by default; there is no good of line buffering,
as all logging is performed linewise - so remove buffering from stdout
also
*/
setbuf(stdout, 0);
}
SYNOPSIS
die()
format [IN] format string
... [IN] arguments to format
*/
void die(const char *format, ...)
{
......
......@@ -19,20 +19,23 @@
/*
Logging facilities.
Two logging streams are supported: error log and info log. Additionally
libdbug may be used for debug information output.
Two logging streams are supported: error log and info log.
Additionally libdbug may be used for debug information output.
ANSI C buffered I/O is used to perform logging.
Logging is performed via stdout/stder, so one can reopen them to point to
ordinary files. To initialize loggin environment log_init() must be called.
ordinary files. To initialize logging environment log_init() must be called.
Rationale:
- no MYSQL_LOG as it has BIN mode, and not easy to fetch from sql_class.h
- no constructors/desctructors to make logging available all the time
Function names are subject to change.
*/
/* Precede error message with date and time and print it to the stdout */
void log_init();
void log_info(const char *format, ...)
#ifdef __GNUC__
__attribute__ ((format(printf, 1, 2)))
......@@ -40,7 +43,6 @@ void log_info(const char *format, ...)
;
/* Precede error message with date and time and print it to the stderr */
void log_error(const char *format, ...)
#ifdef __GNUC__
__attribute__ ((format (printf, 1, 2)))
......@@ -48,30 +50,6 @@ void log_error(const char *format, ...)
;
/*
Now this is simple catchouts for printf (no date/time is logged), to be
able to replace underlying streams in future.
*/
void print_info(const char *format, ...)
#ifdef __GNUC__
__attribute__ ((format (printf, 1, 2)))
#endif
;
void print_error(const char *format, ...)
#ifdef __GNUC__
__attribute__ ((format (printf, 1, 2)))
#endif
;
/* initialize logs */
void log_init();
/* print information to the error log and eixt(1) */
void die(const char *format, ...)
#ifdef __GNUC__
__attribute__ ((format (printf, 1, 2)))
......
......@@ -185,7 +185,7 @@ int Manager::main()
if (check_if_linux_threads(&linux_threads))
{
log_error("Error: can not check if Linux Threads are used.");
log_error("Can not determine thread model.");
return 1;
}
......@@ -215,7 +215,7 @@ int Manager::main()
if (instance_map.init())
{
log_error("Error: can not initialize instance list: out of memory.");
log_error("Can not initialize instance list: out of memory.");
return 1;
}
......@@ -223,7 +223,7 @@ int Manager::main()
if (user_map.init())
{
log_error("Error: can not initialize user list: out of memory.");
log_error("Can not initialize user list: out of memory.");
return 1;
}
......@@ -237,12 +237,12 @@ int Manager::main()
mysqld_safe-compatible mode. Continue, but complain in log.
*/
log_error("Warning: password file does not exist, "
log_info("Warning: password file does not exist, "
"nobody will be able to connect to Instance Manager.");
}
else
{
log_error("Error: %s.", (const char *) err_msg);
log_error("%s.", (const char *) err_msg);
return 1;
}
}
......@@ -290,7 +290,7 @@ int Manager::main()
*/
if (guardian.start(Thread::DETACHED))
{
log_error("Error: can not start Guardian thread.");
log_error("Can not start Guardian thread.");
goto err;
}
......@@ -307,7 +307,7 @@ int Manager::main()
if (flush_instances_status)
{
log_error("Error: can not init instances repository.");
log_error("Can not init instances repository.");
stop_all_threads();
goto err;
}
......@@ -317,7 +317,7 @@ int Manager::main()
if (listener.start(Thread::DETACHED))
{
log_error("Error: can not start Listener thread.");
log_error("Can not start Listener thread.");
stop_all_threads();
goto err;
}
......@@ -339,7 +339,7 @@ int Manager::main()
if ((status= my_sigwait(&mask, &signo)) != 0)
{
log_error("Error: sigwait() failed");
log_error("sigwait() failed");
stop_all_threads();
goto err;
}
......
......@@ -77,24 +77,30 @@ C_MODE_END
This function is complementary to cleanup().
*/
int Mysql_connection::init()
bool Mysql_connection::init()
{
/* Allocate buffers for network I/O */
if (my_net_init(&net, vio))
return 1;
return TRUE;
net.return_status= &status;
/* Initialize random number generator */
{
ulong seed1= (ulong) &rand_st + rand();
ulong seed2= (ulong) rand() + time(0);
randominit(&rand_st, seed1, seed2);
}
/* Fill scramble - server's random message used for handshake */
create_random_string(scramble, SCRAMBLE_LENGTH, &rand_st);
/* We don't support transactions, every query is atomic */
status= SERVER_STATUS_AUTOCOMMIT;
thread_registry->register_thread(&thread_info);
return 0;
return FALSE;
}
......@@ -114,12 +120,17 @@ Mysql_connection::~Mysql_connection()
void Mysql_connection::main()
{
log_info("accepted mysql connection %lu", (unsigned long) connection_id);
log_info("Connection %lu: accepted.", (unsigned long) connection_id);
if (check_connection())
{
log_info("Connection %lu: failed to authorize the user.",
(unsigned long) connection_id);
return;
}
log_info("connection %lu is checked successfully",
log_info("Connection %lu: the user was authorized successfully.",
(unsigned long) connection_id);
vio_keepalive(vio, TRUE);
......@@ -257,8 +268,11 @@ int Mysql_connection::do_command()
packet= (char*) net.read_pos;
enum enum_server_command command= (enum enum_server_command)
(uchar) *packet;
log_info("connection %d: packet_length=%d, command=%d",
(int) connection_id, (int) packet_length, (int) command);
log_info("Connection %lu: received packet (length: %lu; command: %d).",
(unsigned long) connection_id,
(unsigned long) packet_length,
(int) command);
return dispatch_command(command, packet + 1);
}
}
......@@ -268,63 +282,81 @@ int Mysql_connection::dispatch_command(enum enum_server_command command,
{
switch (command) {
case COM_QUIT: // client exit
log_info("query for connection %lu received quit command",
log_info("Connection %lu: received QUIT command.",
(unsigned long) connection_id);
return 1;
case COM_PING:
log_info("query for connection %lu received ping command",
log_info("Connection %lu: received PING command.",
(unsigned long) connection_id);
net_send_ok(&net, connection_id, NULL);
break;
return 0;
case COM_QUERY:
{
log_info("query for connection %d : ----\n%s\n-------------------------",
(int) connection_id,
log_info("Connection %lu: received QUERY command: '%s'.",
(unsigned long) connection_id,
(const char *) packet);
if (Command *command= parse_command(packet))
{
int res= 0;
log_info("query for connection %lu successfully parsed",
log_info("Connection %lu: query parsed successfully.",
(unsigned long) connection_id);
res= command->execute(&net, connection_id);
delete command;
if (!res)
log_info("query for connection %lu executed ok",
{
log_info("Connection %lu: query executed successfully",
(unsigned long) connection_id);
}
else
{
log_info("query for connection %lu executed err=%d",
(unsigned long) connection_id, (int) res);
log_info("Connection %lu: can not execute query (error: %d).",
(unsigned long) connection_id,
(int) res);
net_send_error(&net, res);
return 0;
}
}
else
{
log_error("Connection %lu: can not parse query: out ot resources.",
(unsigned long) connection_id);
net_send_error(&net,ER_OUT_OF_RESOURCES);
return 0;
}
break;
return 0;
}
default:
log_info("query for connection %lu received unknown command",
(unsigned long) connection_id);
log_info("Connection %lu: received unsupported command (%d).",
(unsigned long) connection_id,
(int) command);
net_send_error(&net, ER_UNKNOWN_COM_ERROR);
break;
}
return 0;
}
return 0; /* Just to make compiler happy. */
}
void Mysql_connection::run()
{
if (init())
log_info("Mysql_connection::run(): error initializing thread");
log_error("Connection %lu: can not init handler.",
(unsigned long) connection_id);
else
{
main();
cleanup();
}
delete this;
}
......
......@@ -61,7 +61,7 @@ private:
ulong client_capabilities;
private:
/* The main loop implementation triad */
int init();
bool init();
void main();
void cleanup();
......
......@@ -191,7 +191,8 @@ static struct passwd *check_user(const char *user)
return user_info;
err:
log_error("Fatal error: Can't change to run as user '%s' ; Please check that the user exists!\n", user);
log_error("Can not start under user '%s'.",
(const char *) user);
return NULL;
}
......
......@@ -55,7 +55,7 @@ int create_pid_file(const char *pid_file_name, int pid)
if (!(pid_file= my_fopen(pid_file_name, O_WRONLY | O_CREAT | O_BINARY,
MYF(0))))
{
log_error("Error: can not create pid file '%s': %s (errno: %d)",
log_error("Can not create pid file '%s': %s (errno: %d)",
(const char *) pid_file_name,
(const char *) strerror(errno),
(int) errno);
......@@ -64,7 +64,7 @@ int create_pid_file(const char *pid_file_name, int pid)
if (fprintf(pid_file, "%d\n", (int) pid) <= 0)
{
log_error("Error: can not write to pid file '%s': %s (errno: %d)",
log_error("Can not write to pid file '%s': %s (errno: %d)",
(const char *) pid_file_name,
(const char *) strerror(errno),
(int) errno);
......
......@@ -85,11 +85,11 @@ Thread_registry::~Thread_registry()
void Thread_registry::register_thread(Thread_info *info,
bool send_signal_on_shutdown)
{
DBUG_PRINT("info", ("Thread_registry: registering thread %d...",
(int) info->thread_id));
info->init(send_signal_on_shutdown);
DBUG_PRINT("info", ("Thread_registry: registering thread %lu...",
(unsigned long) info->thread_id));
#ifndef __WIN__
struct sigaction sa;
sa.sa_handler= handle_signal;
......@@ -116,8 +116,8 @@ void Thread_registry::register_thread(Thread_info *info,
void Thread_registry::unregister_thread(Thread_info *info)
{
DBUG_PRINT("info", ("Thread_registry: unregistering thread %d...",
(int) info->thread_id));
DBUG_PRINT("info", ("Thread_registry: unregistering thread %lu...",
(unsigned long) info->thread_id));
pthread_mutex_lock(&LOCK_thread_registry);
info->prev->next= info->next;
......
......@@ -41,7 +41,7 @@ int User::init(const char *line)
name_end= strchr(name_begin, line[0]);
if (name_end == 0 || name_end[1] != ':')
{
log_info("Error: invalid format (unmatched quote) of user line (%s).",
log_error("Invalid format (unmatched quote) of user line (%s).",
(const char *) line);
return 1;
}
......@@ -53,7 +53,7 @@ int User::init(const char *line)
name_end= strchr(name_begin, ':');
if (name_end == 0)
{
log_info("Error: invalid format (no delimiter) of user line (%s).",
log_error("Invalid format (no delimiter) of user line (%s).",
(const char *) line);
return 1;
}
......@@ -63,7 +63,7 @@ int User::init(const char *line)
user_length= name_end - name_begin;
if (user_length > USERNAME_LENGTH)
{
log_info("Error: user name is too long (%d). Max length: %d. "
log_error("User name is too long (%d). Max length: %d. "
"User line: '%s'.",
(int) user_length,
(int) USERNAME_LENGTH,
......@@ -74,7 +74,7 @@ int User::init(const char *line)
password_length= strlen(password);
if (password_length > SCRAMBLED_PASSWORD_CHAR_LENGTH)
{
log_info("Error: password is too long (%d). Max length: %d."
log_error("Password is too long (%d). Max length: %d."
"User line: '%s'.",
(int) password_length,
(int) SCRAMBLED_PASSWORD_CHAR_LENGTH,
......@@ -90,7 +90,7 @@ int User::init(const char *line)
get_salt_from_password(salt, password);
log_info("loaded user '%s'.", user);
log_info("Loaded user '%s'.", (const char *) user);
return 0;
}
......@@ -214,7 +214,7 @@ int User_map::load(const char *password_file_name, const char **err_msg)
return ERR_IO_ERROR;
}
log_info("loading the password database...");
log_info("Loading the password database...");
while (fgets(line, sizeof(line), file))
{
......@@ -292,7 +292,7 @@ int User_map::load(const char *password_file_name, const char **err_msg)
}
}
log_info("the password database loaded successfully.");
log_info("The password database loaded successfully.");
my_fclose(file, MYF(0));
......
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