Commit 6958e328 authored by unknown's avatar unknown

Added option hostname.err


sql/sql_parse.cc:
  added option hostname.err
parent 48f587a8
......@@ -1568,3 +1568,49 @@ void sql_perror(const char *message)
perror(message);
#endif
}
bool flush_error_log()
{
bool result=0;
if (log_error_file[0] != '\0') /* --log-error="" */
{
char err_renamed[FN_REFLEN], *end;
end= strmake(err_renamed,log_error_file,FN_REFLEN-4);
strmov(end, "-old");
#ifdef __WIN__
char err_temp[FN_REFLEN+4];
/*
On Windows is necessary a temporary file for to rename
the current error file.
*/
strmov(strmov(err_temp, err_renamed),"-tmp");
(void) my_delete(err_temp, MYF(0));
if (freopen(err_temp,"a+",stdout))
{
freopen(err_temp,"a+",stderr);
(void) my_delete(err_renamed, MYF(0));
my_rename(log_error_file,err_renamed,MYF(0));
if (freopen(log_error_file,"a+",stdout))
freopen(log_error_file,"a+",stderr);
int fd, bytes;
char buf[IO_SIZE];
if ((fd = my_open(err_temp, O_RDONLY, MYF(0))) >= 0)
{
while ((bytes = (int) my_read(fd, (byte*) buf, IO_SIZE, MYF(0))) > 0)
my_fwrite(stderr, (byte*) buf, (uint) strlen(buf),MYF(0));
my_close(fd, MYF(0));
}
(void) my_delete(err_temp, MYF(0));
}
else
result= 1;
#else
my_rename(log_error_file,err_renamed,MYF(0));
if (freopen(log_error_file,"a+",stdout))
freopen(log_error_file,"a+",stderr);
else
result= 1;
#endif
}
return result;
}
......@@ -627,6 +627,7 @@ extern uchar *days_in_month;
extern char language[LIBLEN],reg_ext[FN_EXTLEN];
extern char glob_hostname[FN_REFLEN], mysql_home[FN_REFLEN];
extern char pidfile_name[FN_REFLEN], time_zone[30], *opt_init_file;
extern char log_error_file[FN_REFLEN];
extern char blob_newline;
extern double log_10[32];
extern ulonglong keybuff_size;
......@@ -813,6 +814,9 @@ extern int sql_cache_hit(THD *thd, char *inBuf, uint length);
/* item.cc */
Item *get_system_var(enum_var_type var_type, LEX_STRING name);
/* log.cc */
bool flush_error_log(void);
/* Some inline functions for more speed */
inline bool add_item_to_list(Item *item)
......
......@@ -262,6 +262,7 @@ my_bool opt_reckless_slave = 0;
ulong back_log, connect_timeout, concurrency;
char mysql_home[FN_REFLEN], pidfile_name[FN_REFLEN], time_zone[30];
char log_error_file[FN_REFLEN];
bool opt_log, opt_update_log, opt_bin_log, opt_slow_log;
bool opt_disable_networking=0, opt_skip_show_db=0;
my_bool opt_enable_named_pipe= 0;
......@@ -278,6 +279,7 @@ static my_string opt_logname=0,opt_update_logname=0,
static char* mysql_home_ptr= mysql_home;
static char* pidfile_name_ptr= pidfile_name;
char* log_error_file_ptr= log_error_file;
static pthread_t select_thread;
static my_bool opt_noacl=0, opt_bootstrap=0, opt_myisam_log=0;
my_bool opt_safe_user_create = 0, opt_no_mix_types = 0;
......@@ -2042,13 +2044,28 @@ int main(int argc, char **argv)
open_log(&mysql_slow_log, glob_hostname, opt_slow_logname, "-slow.log",
NullS, LOG_NORMAL);
#ifdef __WIN__
#define MYSQL_ERR_FILE "mysql.err"
if (!opt_console)
{
freopen(MYSQL_ERR_FILE,"a+",stdout);
freopen(MYSQL_ERR_FILE,"a+",stderr);
#endif
if (log_error_file_ptr != log_error_file)
strmake(log_error_file, log_error_file_ptr, sizeof(log_error_file));
else
{
char *end;
uint length= ((end=strmake(log_error_file,
mysql_real_data_home,
FN_REFLEN-5)) -
log_error_file);
*strxnmov(end, sizeof(log_error_file)-length-1,
glob_hostname, ".err", NullS)= '\0';
}
if (log_error_file[0] != '\0')
if (freopen(log_error_file, "a+", stdout))
freopen(log_error_file, "a+", stderr);
#ifdef __WIN__
}
#endif
if (ha_init())
{
sql_print_error("Can't init databases");
......@@ -2964,7 +2981,8 @@ enum options {
OPT_INNODB_FORCE_RECOVERY,
OPT_BDB_CACHE_SIZE,
OPT_BDB_LOG_BUFFER_SIZE,
OPT_BDB_MAX_LOCK
OPT_BDB_MAX_LOCK,
OPT_ERROR_LOG_FILE
};
......@@ -3253,6 +3271,9 @@ struct my_option my_long_options[] =
{"pid-file", OPT_PID_FILE, "Pid file used by safe_mysqld",
(gptr*) &pidfile_name_ptr, (gptr*) &pidfile_name_ptr, 0, GET_STR,
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"log-error", OPT_ERROR_LOG_FILE, "Log error file",
(gptr*) &log_error_file_ptr, (gptr*) &log_error_file_ptr, 0, GET_STR,
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"port", 'P', "Port number to use for connection.", (gptr*) &mysql_port,
(gptr*) &mysql_port, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"reckless-slave", OPT_RECKLESS_SLAVE, "For debugging", 0, 0, 0, GET_NO_ARG,
......
......@@ -491,6 +491,7 @@ struct show_var_st init_vars[]= {
{sys_net_write_timeout.name,(char*) &sys_net_write_timeout, SHOW_SYS},
{"open_files_limit", (char*) &open_files_limit, SHOW_LONG},
{"pid_file", (char*) pidfile_name, SHOW_CHAR},
{"log_error", (char*) log_error_file, SHOW_CHAR},
{"port", (char*) &mysql_port, SHOW_INT},
{"protocol_version", (char*) &protocol_version, SHOW_INT},
{sys_read_buff_size.name, (char*) &sys_read_buff_size, SHOW_SYS},
......
......@@ -3407,6 +3407,8 @@ bool reload_acl_and_cache(THD *thd, ulong options, TABLE_LIST *tables)
mysql_slow_log.new_file(1);
if (ha_flush_logs())
result=1;
if (flush_error_log())
result=1;
}
#ifdef HAVE_QUERY_CACHE
if (options & REFRESH_QUERY_CACHE_FREE)
......
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