mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
fix for #1344
handling of init-file option added to embedded library main problem was killing of output (resulting recordsets etc) i added checks for empty output in Protocol:: methods better solution could be special Protocol_nul class to redirect results to nowhere
This commit is contained in:
@ -389,6 +389,15 @@ int STDCALL mysql_server_init(int argc, char **argv, char **groups)
|
|||||||
sql_print_error("Warning: Can't create thread to manage maintenance");
|
sql_print_error("Warning: Can't create thread to manage maintenance");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (opt_init_file)
|
||||||
|
{
|
||||||
|
if (read_init_file(opt_init_file))
|
||||||
|
{
|
||||||
|
mysql_server_end();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Update mysqld variables from client variables if set
|
Update mysqld variables from client variables if set
|
||||||
The client variables are set also by get_one_option() in mysqld.cc
|
The client variables are set also by get_one_option() in mysqld.cc
|
||||||
@ -516,6 +525,9 @@ bool Protocol::send_fields(List<Item> *list, uint flag)
|
|||||||
|
|
||||||
DBUG_ENTER("send_fields");
|
DBUG_ENTER("send_fields");
|
||||||
|
|
||||||
|
if (!mysql) // bootstrap file handling
|
||||||
|
DBUG_RETURN(0);
|
||||||
|
|
||||||
field_count= list->elements;
|
field_count= list->elements;
|
||||||
field_alloc= &mysql->field_alloc;
|
field_alloc= &mysql->field_alloc;
|
||||||
if (!(client_field= thd->mysql->fields=
|
if (!(client_field= thd->mysql->fields=
|
||||||
@ -577,6 +589,9 @@ bool Protocol::send_records_num(List<Item> *list, ulonglong records)
|
|||||||
|
|
||||||
bool Protocol::write()
|
bool Protocol::write()
|
||||||
{
|
{
|
||||||
|
if (!thd->mysql) // bootstrap file handling
|
||||||
|
return false;
|
||||||
|
|
||||||
*next_field= 0;
|
*next_field= 0;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -622,12 +637,12 @@ send_ok(THD *thd,ha_rows affected_rows,ulonglong id,const char *message)
|
|||||||
{
|
{
|
||||||
DBUG_ENTER("send_ok");
|
DBUG_ENTER("send_ok");
|
||||||
MYSQL *mysql= current_thd->mysql;
|
MYSQL *mysql= current_thd->mysql;
|
||||||
|
if (!mysql) // bootstrap file handling
|
||||||
|
DBUG_VOID_RETURN;
|
||||||
mysql->affected_rows= affected_rows;
|
mysql->affected_rows= affected_rows;
|
||||||
mysql->insert_id= id;
|
mysql->insert_id= id;
|
||||||
if (message)
|
if (message)
|
||||||
{
|
|
||||||
strmake(thd->net.last_error, message, sizeof(thd->net.last_error)-1);
|
strmake(thd->net.last_error, message, sizeof(thd->net.last_error)-1);
|
||||||
}
|
|
||||||
DBUG_VOID_RETURN;
|
DBUG_VOID_RETURN;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -684,6 +699,9 @@ bool Protocol_simple::store_null()
|
|||||||
bool Protocol::net_store_data(const char *from, uint length)
|
bool Protocol::net_store_data(const char *from, uint length)
|
||||||
{
|
{
|
||||||
char *field_buf;
|
char *field_buf;
|
||||||
|
if (!thd->mysql) // bootstrap file handling
|
||||||
|
return false;
|
||||||
|
|
||||||
if (!(field_buf=alloc_root(alloc, length + sizeof(uint) + 1)))
|
if (!(field_buf=alloc_root(alloc, length + sizeof(uint) + 1)))
|
||||||
return true;
|
return true;
|
||||||
*(uint *)field_buf= length;
|
*(uint *)field_buf= length;
|
||||||
|
@ -2769,7 +2769,6 @@ static int bootstrap(FILE *file)
|
|||||||
{
|
{
|
||||||
int error= 0;
|
int error= 0;
|
||||||
DBUG_ENTER("bootstrap");
|
DBUG_ENTER("bootstrap");
|
||||||
#ifndef EMBEDDED_LIBRARY // TODO: Enable this
|
|
||||||
|
|
||||||
THD *thd= new THD;
|
THD *thd= new THD;
|
||||||
thd->bootstrap=1;
|
thd->bootstrap=1;
|
||||||
@ -2781,6 +2780,7 @@ static int bootstrap(FILE *file)
|
|||||||
thread_count++;
|
thread_count++;
|
||||||
|
|
||||||
bootstrap_file=file;
|
bootstrap_file=file;
|
||||||
|
#ifndef EMBEDDED_LIBRARY // TODO: Enable this
|
||||||
if (pthread_create(&thd->real_id,&connection_attrib,handle_bootstrap,
|
if (pthread_create(&thd->real_id,&connection_attrib,handle_bootstrap,
|
||||||
(void*) thd))
|
(void*) thd))
|
||||||
{
|
{
|
||||||
@ -2795,11 +2795,17 @@ static int bootstrap(FILE *file)
|
|||||||
DBUG_PRINT("quit",("One thread died (count=%u)",thread_count));
|
DBUG_PRINT("quit",("One thread died (count=%u)",thread_count));
|
||||||
}
|
}
|
||||||
(void) pthread_mutex_unlock(&LOCK_thread_count);
|
(void) pthread_mutex_unlock(&LOCK_thread_count);
|
||||||
|
#else
|
||||||
|
thd->mysql= 0;
|
||||||
|
handle_bootstrap((void *)thd);
|
||||||
|
#endif
|
||||||
|
|
||||||
error= thd->is_fatal_error;
|
error= thd->is_fatal_error;
|
||||||
|
#ifndef EMBEDDED_LIBRARY
|
||||||
net_end(&thd->net);
|
net_end(&thd->net);
|
||||||
|
#endif
|
||||||
thd->cleanup();
|
thd->cleanup();
|
||||||
delete thd;
|
delete thd;
|
||||||
#endif /* EMBEDDED_LIBRARY */
|
|
||||||
DBUG_RETURN(error);
|
DBUG_RETURN(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -932,6 +932,8 @@ end_thread:
|
|||||||
return(0); /* purecov: deadcode */
|
return(0); /* purecov: deadcode */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif /* EMBEDDED_LIBRARY */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Execute commands from bootstrap_file.
|
Execute commands from bootstrap_file.
|
||||||
Used when creating the initial grant tables
|
Used when creating the initial grant tables
|
||||||
@ -946,12 +948,15 @@ extern "C" pthread_handler_decl(handle_bootstrap,arg)
|
|||||||
/* The following must be called before DBUG_ENTER */
|
/* The following must be called before DBUG_ENTER */
|
||||||
if (my_thread_init() || thd->store_globals())
|
if (my_thread_init() || thd->store_globals())
|
||||||
{
|
{
|
||||||
|
#ifndef EMBEDDED_LIBRARY
|
||||||
close_connection(thd, ER_OUT_OF_RESOURCES, 1);
|
close_connection(thd, ER_OUT_OF_RESOURCES, 1);
|
||||||
|
#endif
|
||||||
thd->fatal_error();
|
thd->fatal_error();
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
DBUG_ENTER("handle_bootstrap");
|
DBUG_ENTER("handle_bootstrap");
|
||||||
|
|
||||||
|
#ifndef EMBEDDED_LIBRARY
|
||||||
pthread_detach_this_thread();
|
pthread_detach_this_thread();
|
||||||
thd->thread_stack= (char*) &thd;
|
thd->thread_stack= (char*) &thd;
|
||||||
#if !defined(__WIN__) && !defined(OS2) && !defined(__NETWARE__)
|
#if !defined(__WIN__) && !defined(OS2) && !defined(__NETWARE__)
|
||||||
@ -959,6 +964,7 @@ extern "C" pthread_handler_decl(handle_bootstrap,arg)
|
|||||||
VOID(sigemptyset(&set)); // Get mask in use
|
VOID(sigemptyset(&set)); // Get mask in use
|
||||||
VOID(pthread_sigmask(SIG_UNBLOCK,&set,&thd->block_signals));
|
VOID(pthread_sigmask(SIG_UNBLOCK,&set,&thd->block_signals));
|
||||||
#endif
|
#endif
|
||||||
|
#endif /* EMBEDDED_LIBRARY */
|
||||||
|
|
||||||
if (thd->variables.max_join_size == HA_POS_ERROR)
|
if (thd->variables.max_join_size == HA_POS_ERROR)
|
||||||
thd->options |= OPTION_BIG_SELECTS;
|
thd->options |= OPTION_BIG_SELECTS;
|
||||||
@ -980,6 +986,7 @@ extern "C" pthread_handler_decl(handle_bootstrap,arg)
|
|||||||
thd->query= thd->memdup_w_gap(buff, length+1, thd->db_length+1);
|
thd->query= thd->memdup_w_gap(buff, length+1, thd->db_length+1);
|
||||||
thd->query[length] = '\0';
|
thd->query[length] = '\0';
|
||||||
thd->query_id=query_id++;
|
thd->query_id=query_id++;
|
||||||
|
#ifndef NO_EMBEDDED_ACCESS_CHECKS
|
||||||
if (mqh_used && thd->user_connect && check_mqh(thd, SQLCOM_END))
|
if (mqh_used && thd->user_connect && check_mqh(thd, SQLCOM_END))
|
||||||
{
|
{
|
||||||
thd->net.error = 0;
|
thd->net.error = 0;
|
||||||
@ -987,6 +994,7 @@ extern "C" pthread_handler_decl(handle_bootstrap,arg)
|
|||||||
free_root(&thd->mem_root,MYF(MY_KEEP_PREALLOC));
|
free_root(&thd->mem_root,MYF(MY_KEEP_PREALLOC));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
mysql_parse(thd,thd->query,length);
|
mysql_parse(thd,thd->query,length);
|
||||||
close_thread_tables(thd); // Free tables
|
close_thread_tables(thd); // Free tables
|
||||||
if (thd->is_fatal_error)
|
if (thd->is_fatal_error)
|
||||||
@ -997,17 +1005,17 @@ extern "C" pthread_handler_decl(handle_bootstrap,arg)
|
|||||||
|
|
||||||
/* thd->fatal_error should be set in case something went wrong */
|
/* thd->fatal_error should be set in case something went wrong */
|
||||||
end:
|
end:
|
||||||
|
#ifndef EMBEDDED_LIBRARY
|
||||||
(void) pthread_mutex_lock(&LOCK_thread_count);
|
(void) pthread_mutex_lock(&LOCK_thread_count);
|
||||||
thread_count--;
|
thread_count--;
|
||||||
(void) pthread_mutex_unlock(&LOCK_thread_count);
|
(void) pthread_mutex_unlock(&LOCK_thread_count);
|
||||||
(void) pthread_cond_broadcast(&COND_thread_count);
|
(void) pthread_cond_broadcast(&COND_thread_count);
|
||||||
my_thread_end();
|
my_thread_end();
|
||||||
pthread_exit(0);
|
pthread_exit(0);
|
||||||
|
#endif
|
||||||
DBUG_RETURN(0); // Never reached
|
DBUG_RETURN(0); // Never reached
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* EMBEDDED_LIBRARY */
|
|
||||||
|
|
||||||
/* This works because items are allocated with sql_alloc() */
|
/* This works because items are allocated with sql_alloc() */
|
||||||
|
|
||||||
void free_items(Item *item)
|
void free_items(Item *item)
|
||||||
|
Reference in New Issue
Block a user