Commit ab632586 authored by sasha@mysql.sashanet.com's avatar sasha@mysql.sashanet.com

Merge work:/home/bk/mysql-4.0

into mysql.sashanet.com:/home/sasha/src/bk/mysql-4.0
parents 02278726 77e2af48
......@@ -207,7 +207,7 @@ static void die(const char* fmt, ...);
static void init_var_hash();
static byte* get_var_key(const byte* rec, uint* len,
my_bool __attribute__((unused)) t);
static VAR* var_init(const char* name, int name_len, const char* val,
static VAR* var_init(VAR* v, const char* name, int name_len, const char* val,
int val_len);
static void var_free(void* v);
......@@ -529,7 +529,7 @@ static VAR* var_obtain(char* name, int len)
VAR* v;
if((v = (VAR*)hash_search(&var_hash, name, len)))
return v;
v = var_init(name, len, "", 0);
v = var_init(0, name, len, "", 0);
hash_insert(&var_hash, (byte*)v);
return v;
}
......@@ -678,6 +678,7 @@ int do_system(struct st_query* q)
{
char* p=q->first_argument;
VAR v;
var_init(&v, 0, 0, 0, 0);
eval_expr(&v, p, 0); /* NULL terminated */
if (v.str_val_len)
{
......@@ -697,6 +698,7 @@ int do_echo(struct st_query* q)
{
char* p=q->first_argument;
VAR v;
var_init(&v,0,0,0,0);
eval_expr(&v, p, 0); /* NULL terminated */
if (v.str_val_len)
{
......@@ -1172,6 +1174,7 @@ int do_while(struct st_query* q)
char* p=q->first_argument;
const char* expr_start, *expr_end;
VAR v;
var_init(&v,0,0,0,0);
if (cur_block == block_stack_end)
die("Nesting too deeply");
if (!*block_ok)
......@@ -1837,29 +1840,32 @@ static byte* get_var_key(const byte* var, uint* len,
return (byte*)key;
}
static VAR* var_init(const char* name, int name_len, const char* val,
static VAR* var_init(VAR* v, const char* name, int name_len, const char* val,
int val_len)
{
int val_alloc_len;
VAR* tmp_var;
if(!name_len)
if(!name_len && name)
name_len = strlen(name);
if(!val_len)
if(!val_len && val)
val_len = strlen(val) ;
val_alloc_len = val_len + 16; /* room to grow */
if(!(tmp_var = (VAR*)my_malloc(sizeof(*tmp_var)
if(!(tmp_var=v) && !(tmp_var = (VAR*)my_malloc(sizeof(*tmp_var)
+ name_len, MYF(MY_WME))))
die("Out of memory");
tmp_var->name = (char*)tmp_var + sizeof(*tmp_var);
tmp_var->name = (name) ? (char*)tmp_var + sizeof(*tmp_var) : 0;
if(!(tmp_var->str_val = my_malloc(val_alloc_len, MYF(MY_WME))))
die("Out of memory");
memcpy(tmp_var->name, name, name_len);
memcpy(tmp_var->str_val, val, val_len + 1);
if(val)
memcpy(tmp_var->str_val, val, val_len + 1);
tmp_var->name_len = name_len;
tmp_var->str_val_len = val_len;
tmp_var->alloced_len = val_alloc_len;
tmp_var->int_val = atoi(val);
tmp_var->int_val = (val) ? atoi(val) : 0;
tmp_var->int_dirty = 0;
return tmp_var;
}
......@@ -1878,7 +1884,7 @@ static void var_from_env(const char* name, const char* def_val)
if(!(tmp = getenv(name)))
tmp = def_val;
v = var_init(name, 0, tmp, 0);
v = var_init(0, name, 0, tmp, 0);
hash_insert(&var_hash, (byte*)v);
}
......
......@@ -514,17 +514,19 @@ bool MYSQL_LOG::is_active(const char* log_file_name)
return inited && !strcmp(log_file_name, this->log_file_name);
}
void MYSQL_LOG::new_file()
void MYSQL_LOG::new_file(bool inside_mutex)
{
// only rotate open logs that are marked non-rotatable
// (binlog with constant name are non-rotatable)
if (is_open() && ! no_rotate)
{
char new_name[FN_REFLEN], *old_name=name;
VOID(pthread_mutex_lock(&LOCK_log));
if (!inside_mutex)
VOID(pthread_mutex_lock(&LOCK_log));
if (generate_new_name(new_name, name))
{
VOID(pthread_mutex_unlock(&LOCK_log));
if (!inside_mutex)
VOID(pthread_mutex_unlock(&LOCK_log));
return; // Something went wrong
}
if (log_type == LOG_BIN)
......@@ -551,7 +553,8 @@ void MYSQL_LOG::new_file()
my_free(old_name,MYF(0));
last_time=query_start=0;
write_error=0;
VOID(pthread_mutex_unlock(&LOCK_log));
if (!inside_mutex)
VOID(pthread_mutex_unlock(&LOCK_log));
}
}
......@@ -729,9 +732,9 @@ err:
if (file == &log_file)
VOID(pthread_cond_broadcast(&COND_binlog_update));
}
VOID(pthread_mutex_unlock(&LOCK_log));
if(should_rotate)
new_file();
new_file(1); // inside mutex
VOID(pthread_mutex_unlock(&LOCK_log));
return error;
}
......@@ -817,12 +820,10 @@ bool MYSQL_LOG::write(Load_log_event* event_info)
VOID(pthread_cond_broadcast(&COND_binlog_update));
}
}
if(should_rotate)
new_file(1); // inside mutex
VOID(pthread_mutex_unlock(&LOCK_log));
}
if(should_rotate)
new_file();
return error;
}
......
......@@ -1498,6 +1498,13 @@ static void open_log(MYSQL_LOG *log, const char *hostname,
strmov(strcend(tmp,'.'),extension);
opt_name=tmp;
}
// get rid of extention if the log is binary to avoid problems
if (type == LOG_BIN)
{
char* p = strrchr(opt_name, FN_EXTCHAR);
if (p)
*p = 0;
}
log->open(opt_name,type);
}
......
......@@ -80,7 +80,7 @@ public:
void init(enum_log_type log_type_arg);
void open(const char *log_name,enum_log_type log_type,
const char *new_name=0);
void new_file(void);
void new_file(bool inside_mutex=0);
bool open_index(int options);
void close_index();
bool write(THD *thd, enum enum_server_command command,const char *format,...);
......
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