From 9dcce9b0f33619d98b12d9e266bee55518edeabe Mon Sep 17 00:00:00 2001 From: "hf@deer.(none)" <> Date: Mon, 29 Sep 2003 21:07:53 +0500 Subject: [PATCH] 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 --- libmysqld/lib_sql.cc | 22 ++++++++++++++++++++-- sql/mysqld.cc | 10 ++++++++-- sql/sql_parse.cc | 12 ++++++++++-- 3 files changed, 38 insertions(+), 6 deletions(-) diff --git a/libmysqld/lib_sql.cc b/libmysqld/lib_sql.cc index 8d20dd9ba34..9b0b32b628e 100644 --- a/libmysqld/lib_sql.cc +++ b/libmysqld/lib_sql.cc @@ -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"); } + if (opt_init_file) + { + if (read_init_file(opt_init_file)) + { + mysql_server_end(); + return 1; + } + } + /* Update mysqld variables from client variables if set The client variables are set also by get_one_option() in mysqld.cc @@ -516,6 +525,9 @@ bool Protocol::send_fields(List *list, uint flag) DBUG_ENTER("send_fields"); + if (!mysql) // bootstrap file handling + DBUG_RETURN(0); + field_count= list->elements; field_alloc= &mysql->field_alloc; if (!(client_field= thd->mysql->fields= @@ -577,6 +589,9 @@ bool Protocol::send_records_num(List *list, ulonglong records) bool Protocol::write() { + if (!thd->mysql) // bootstrap file handling + return false; + *next_field= 0; return false; } @@ -622,12 +637,12 @@ send_ok(THD *thd,ha_rows affected_rows,ulonglong id,const char *message) { DBUG_ENTER("send_ok"); MYSQL *mysql= current_thd->mysql; + if (!mysql) // bootstrap file handling + DBUG_VOID_RETURN; mysql->affected_rows= affected_rows; mysql->insert_id= id; if (message) - { strmake(thd->net.last_error, message, sizeof(thd->net.last_error)-1); - } DBUG_VOID_RETURN; } @@ -684,6 +699,9 @@ bool Protocol_simple::store_null() bool Protocol::net_store_data(const char *from, uint length) { char *field_buf; + if (!thd->mysql) // bootstrap file handling + return false; + if (!(field_buf=alloc_root(alloc, length + sizeof(uint) + 1))) return true; *(uint *)field_buf= length; diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 07749128837..6213c43b80b 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -2769,7 +2769,6 @@ static int bootstrap(FILE *file) { int error= 0; DBUG_ENTER("bootstrap"); -#ifndef EMBEDDED_LIBRARY // TODO: Enable this THD *thd= new THD; thd->bootstrap=1; @@ -2781,6 +2780,7 @@ static int bootstrap(FILE *file) thread_count++; bootstrap_file=file; +#ifndef EMBEDDED_LIBRARY // TODO: Enable this if (pthread_create(&thd->real_id,&connection_attrib,handle_bootstrap, (void*) thd)) { @@ -2795,11 +2795,17 @@ static int bootstrap(FILE *file) DBUG_PRINT("quit",("One thread died (count=%u)",thread_count)); } (void) pthread_mutex_unlock(&LOCK_thread_count); +#else + thd->mysql= 0; + handle_bootstrap((void *)thd); +#endif + error= thd->is_fatal_error; +#ifndef EMBEDDED_LIBRARY net_end(&thd->net); +#endif thd->cleanup(); delete thd; -#endif /* EMBEDDED_LIBRARY */ DBUG_RETURN(error); } diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 1f5b433b405..b0dd2437fd7 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -932,6 +932,8 @@ end_thread: return(0); /* purecov: deadcode */ } +#endif /* EMBEDDED_LIBRARY */ + /* Execute commands from bootstrap_file. 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 */ if (my_thread_init() || thd->store_globals()) { +#ifndef EMBEDDED_LIBRARY close_connection(thd, ER_OUT_OF_RESOURCES, 1); +#endif thd->fatal_error(); goto end; } DBUG_ENTER("handle_bootstrap"); +#ifndef EMBEDDED_LIBRARY pthread_detach_this_thread(); thd->thread_stack= (char*) &thd; #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(pthread_sigmask(SIG_UNBLOCK,&set,&thd->block_signals)); #endif +#endif /* EMBEDDED_LIBRARY */ if (thd->variables.max_join_size == HA_POS_ERROR) 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[length] = '\0'; thd->query_id=query_id++; +#ifndef NO_EMBEDDED_ACCESS_CHECKS if (mqh_used && thd->user_connect && check_mqh(thd, SQLCOM_END)) { 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)); break; } +#endif mysql_parse(thd,thd->query,length); close_thread_tables(thd); // Free tables 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 */ end: +#ifndef EMBEDDED_LIBRARY (void) pthread_mutex_lock(&LOCK_thread_count); thread_count--; (void) pthread_mutex_unlock(&LOCK_thread_count); (void) pthread_cond_broadcast(&COND_thread_count); my_thread_end(); pthread_exit(0); +#endif DBUG_RETURN(0); // Never reached } -#endif /* EMBEDDED_LIBRARY */ - /* This works because items are allocated with sql_alloc() */ void free_items(Item *item)