Commit 42799cc5 authored by hf@deer.(none)'s avatar hf@deer.(none)

Fix for #2126 (mysql_server_init call shouldn't be needed)

now mysql_server_init is called from mysql_init with fake parameters
mysql_once_init code included to mysql_server_init.
embedded-specific initialization is in init_embedded_server function
parent 2b53eef5
...@@ -86,5 +86,4 @@ extern const char *client_errors[]; /* Error messages */ ...@@ -86,5 +86,4 @@ extern const char *client_errors[]; /* Error messages */
#define CR_SHARED_MEMORY_CONNECT_SET_ERROR 2045 #define CR_SHARED_MEMORY_CONNECT_SET_ERROR 2045
#define CR_CONN_UNKNOW_PROTOCOL 2046 #define CR_CONN_UNKNOW_PROTOCOL 2046
#define CR_INVALID_CONN_HANDLE 2047 #define CR_INVALID_CONN_HANDLE 2047
#define CR_MYSQL_SERVER_INIT_MISSED 2048 #define CR_SECURE_AUTH 2048
#define CR_SECURE_AUTH 2049
...@@ -638,9 +638,6 @@ int STDCALL mysql_drop_db(MYSQL *mysql, const char *DB); ...@@ -638,9 +638,6 @@ int STDCALL mysql_drop_db(MYSQL *mysql, const char *DB);
(*(mysql)->methods->advanced_command)(mysql, command, \ (*(mysql)->methods->advanced_command)(mysql, command, \
NullS, 0, arg, length, skip_check) NullS, 0, arg, length, skip_check)
unsigned long net_safe_read(MYSQL* mysql); unsigned long net_safe_read(MYSQL* mysql);
void mysql_once_init(void);
extern my_bool server_inited;
#ifdef __NETWARE__ #ifdef __NETWARE__
#pragma pack(pop) /* restore alignment */ #pragma pack(pop) /* restore alignment */
......
...@@ -58,3 +58,14 @@ int cli_stmt_execute(MYSQL_STMT *stmt); ...@@ -58,3 +58,14 @@ int cli_stmt_execute(MYSQL_STMT *stmt);
MYSQL_DATA * cli_read_binary_rows(MYSQL_STMT *stmt); MYSQL_DATA * cli_read_binary_rows(MYSQL_STMT *stmt);
int cli_unbuffered_fetch(MYSQL *mysql, char **row); int cli_unbuffered_fetch(MYSQL *mysql, char **row);
const char * cli_read_statistic(MYSQL *mysql); const char * cli_read_statistic(MYSQL *mysql);
#ifdef EMBEDDED_LIBRARY
int init_embedded_server(int argc, char **argv, char **groups);
void end_embedded_server();
#else
/* Prevent warnings of unused parameters */
#define init_embedded_server(a,b,c) ((void)a, (void)b, (void)c, 0)
#define end_embedded_server()
#endif /*EMBEDDED_LIBRARY*/
...@@ -72,7 +72,6 @@ const char *client_errors[]= ...@@ -72,7 +72,6 @@ const char *client_errors[]=
"Can't open shared memory. Can't send the request event to server (%lu)", "Can't open shared memory. Can't send the request event to server (%lu)",
"Wrong or unknown protocol", "Wrong or unknown protocol",
"Invalid connection handle", "Invalid connection handle",
"mysql_server_init wasn't called",
"Connection using old (pre 4.1.1) authentication protocol refused (client option 'secure_auth' enabled)" "Connection using old (pre 4.1.1) authentication protocol refused (client option 'secure_auth' enabled)"
}; };
...@@ -129,7 +128,6 @@ const char *client_errors[]= ...@@ -129,7 +128,6 @@ const char *client_errors[]=
"Can't open shared memory. Can't send the request event to server (%lu)", "Can't open shared memory. Can't send the request event to server (%lu)",
"Wrong or unknown protocol", "Wrong or unknown protocol",
"Invalid connection handle", "Invalid connection handle",
"mysql_server_init wasn't called",
"Connection using old (pre 4.1.1) authentication protocol refused (client option 'secure_auth' enabled)" "Connection using old (pre 4.1.1) authentication protocol refused (client option 'secure_auth' enabled)"
}; };
...@@ -184,7 +182,6 @@ const char *client_errors[]= ...@@ -184,7 +182,6 @@ const char *client_errors[]=
"Can't open shared memory. Can't send the request event to server (%lu)", "Can't open shared memory. Can't send the request event to server (%lu)",
"Wrong or unknown protocol", "Wrong or unknown protocol",
"Invalid connection handle", "Invalid connection handle",
"mysql_server_init wasn't called",
"Connection using old (pre 4.1.1) authentication protocol refused (client option 'secure_auth' enabled)" "Connection using old (pre 4.1.1) authentication protocol refused (client option 'secure_auth' enabled)"
}; };
#endif #endif
......
...@@ -94,8 +94,9 @@ my_bool stmt_close(MYSQL_STMT *stmt, my_bool skip_list); ...@@ -94,8 +94,9 @@ my_bool stmt_close(MYSQL_STMT *stmt, my_bool skip_list);
static my_bool mysql_client_init= 0; static my_bool mysql_client_init= 0;
static my_bool org_my_init_done= 0; static my_bool org_my_init_done= 0;
void mysql_once_init(void) int STDCALL mysql_server_init(int argc, char **argv, char **groups)
{ {
int result= 0;
if (!mysql_client_init) if (!mysql_client_init)
{ {
mysql_client_init=1; mysql_client_init=1;
...@@ -131,24 +132,18 @@ void mysql_once_init(void) ...@@ -131,24 +132,18 @@ void mysql_once_init(void)
#if defined(SIGPIPE) && !defined(__WIN__) #if defined(SIGPIPE) && !defined(__WIN__)
(void) signal(SIGPIPE, SIG_IGN); (void) signal(SIGPIPE, SIG_IGN);
#endif #endif
result= init_embedded_server(argc, argv, groups);
} }
#ifdef THREAD #ifdef THREAD
else else
my_thread_init(); /* Init if new thread */ my_thread_init(); /* Init if new thread */
#endif #endif
} return result;
#ifndef EMBEDDED_LIBRARY
int STDCALL mysql_server_init(int argc __attribute__((unused)),
char **argv __attribute__((unused)),
char **groups __attribute__((unused)))
{
mysql_once_init();
return 0;
} }
void STDCALL mysql_server_end() void STDCALL mysql_server_end()
{ {
end_embedded_server();
/* If library called my_init(), free memory allocated by it */ /* If library called my_init(), free memory allocated by it */
if (!org_my_init_done) if (!org_my_init_done)
{ {
...@@ -163,8 +158,6 @@ void STDCALL mysql_server_end() ...@@ -163,8 +158,6 @@ void STDCALL mysql_server_end()
mysql_client_init= org_my_init_done= 0; mysql_client_init= org_my_init_done= 0;
} }
#endif /*EMBEDDED_LIBRARY*/
my_bool STDCALL mysql_thread_init() my_bool STDCALL mysql_thread_init()
{ {
#ifdef THREAD #ifdef THREAD
......
...@@ -28,5 +28,4 @@ extern void init_embedded_mysql(MYSQL *mysql, int client_flag, char *db); ...@@ -28,5 +28,4 @@ extern void init_embedded_mysql(MYSQL *mysql, int client_flag, char *db);
extern void *create_embedded_thd(int client_flag, char *db); extern void *create_embedded_thd(int client_flag, char *db);
extern MYSQL_METHODS embedded_methods; extern MYSQL_METHODS embedded_methods;
void free_old_query(MYSQL *mysql); void free_old_query(MYSQL *mysql);
extern my_bool server_inited;
C_MODE_END C_MODE_END
...@@ -42,9 +42,6 @@ C_MODE_START ...@@ -42,9 +42,6 @@ C_MODE_START
#include "errmsg.h" #include "errmsg.h"
#include <sql_common.h> #include <sql_common.h>
static my_bool org_my_init_done;
my_bool server_inited;
static my_bool static my_bool
emb_advanced_command(MYSQL *mysql, enum enum_server_command command, emb_advanced_command(MYSQL *mysql, enum enum_server_command command,
const char *header, ulong header_length, const char *header, ulong header_length,
...@@ -305,7 +302,7 @@ extern "C" ...@@ -305,7 +302,7 @@ extern "C"
char ** copy_arguments_ptr= 0; char ** copy_arguments_ptr= 0;
int STDCALL mysql_server_init(int argc, char **argv, char **groups) int init_embedded_server(int argc, char **argv, char **groups)
{ {
char glob_hostname[FN_REFLEN]; char glob_hostname[FN_REFLEN];
...@@ -329,17 +326,7 @@ int STDCALL mysql_server_init(int argc, char **argv, char **groups) ...@@ -329,17 +326,7 @@ int STDCALL mysql_server_init(int argc, char **argv, char **groups)
if (!groups) if (!groups)
groups= (char**) fake_groups; groups= (char**) fake_groups;
my_progname= (char *)"mysql_embedded";
/* Only call MY_INIT() if it hasn't been called before */
if (!server_inited)
{
server_inited=1;
org_my_init_done=my_init_done;
}
if (!org_my_init_done)
{
MY_INIT((char *)"mysql_embedded"); // init my_sys library & pthreads
}
if (init_common_variables("my", *argcp, *argvp, (const char **)groups)) if (init_common_variables("my", *argcp, *argvp, (const char **)groups))
{ {
...@@ -438,14 +425,11 @@ int STDCALL mysql_server_init(int argc, char **argv, char **groups) ...@@ -438,14 +425,11 @@ int STDCALL mysql_server_init(int argc, char **argv, char **groups)
return 0; return 0;
} }
void STDCALL mysql_server_end() void end_embedded_server()
{ {
my_free((char*) copy_arguments_ptr, MYF(MY_ALLOW_ZERO_PTR)); my_free((char*) copy_arguments_ptr, MYF(MY_ALLOW_ZERO_PTR));
copy_arguments_ptr=0; copy_arguments_ptr=0;
clean_up(0); clean_up(0);
/* If library called my_init(), free memory allocated by it */
if (!org_my_init_done)
my_end(0);
} }
} /* extern "C" */ } /* extern "C" */
......
...@@ -163,20 +163,12 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user, ...@@ -163,20 +163,12 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
db ? db : "(Null)", db ? db : "(Null)",
user ? user : "(Null)")); user ? user : "(Null)"));
#if defined(EMBEDDED_LIBRARY) || !defined(DBUG_OFF)
if (!server_inited)
{
mysql->net.last_errno=CR_MYSQL_SERVER_INIT_MISSED;
strmov(mysql->net.last_error,ER(mysql->net.last_errno));
goto error;
}
#endif
if (mysql->options.methods_to_use == MYSQL_OPT_USE_REMOTE_CONNECTION || if (mysql->options.methods_to_use == MYSQL_OPT_USE_REMOTE_CONNECTION ||
(mysql->options.methods_to_use == MYSQL_OPT_GUESS_CONNECTION && (mysql->options.methods_to_use == MYSQL_OPT_GUESS_CONNECTION &&
host && strcmp(host,LOCAL_HOST))) host && strcmp(host,LOCAL_HOST)))
cli_mysql_real_connect(mysql, host, user, DBUG_RETURN(cli_mysql_real_connect(mysql, host, user,
passwd, db, port, unix_socket, client_flag); passwd, db, port,
unix_socket, client_flag));
mysql->methods= &embedded_methods; mysql->methods= &embedded_methods;
......
...@@ -1310,7 +1310,8 @@ read_one_row(MYSQL *mysql,uint fields,MYSQL_ROW row, ulong *lengths) ...@@ -1310,7 +1310,8 @@ read_one_row(MYSQL *mysql,uint fields,MYSQL_ROW row, ulong *lengths)
MYSQL * STDCALL MYSQL * STDCALL
mysql_init(MYSQL *mysql) mysql_init(MYSQL *mysql)
{ {
mysql_once_init(); if (mysql_server_init(0, NULL, NULL))
return 0;
if (!mysql) if (!mysql)
{ {
if (!(mysql=(MYSQL*) my_malloc(sizeof(*mysql),MYF(MY_WME | MY_ZEROFILL)))) if (!(mysql=(MYSQL*) my_malloc(sizeof(*mysql),MYF(MY_WME | MY_ZEROFILL))))
......
...@@ -32,3 +32,5 @@ ...@@ -32,3 +32,5 @@
#undef HAVE_SMEM #undef HAVE_SMEM
#undef _CUSTOMCONFIG_ #undef _CUSTOMCONFIG_
#define mysql_server_init(a,b,c) FALSE
...@@ -54,6 +54,12 @@ ...@@ -54,6 +54,12 @@
#ifdef EMBEDDED_LIBRARY #ifdef EMBEDDED_LIBRARY
#undef MYSQL_SERVER
#ifndef MYSQL_CLIENT
#define MYSQL_CLIENT
#endif
#undef net_flush #undef net_flush
extern "C" { extern "C" {
......
...@@ -38,8 +38,3 @@ void my_net_local_init(NET *net) ...@@ -38,8 +38,3 @@ void my_net_local_init(NET *net)
} }
} }
extern "C" {
void mysql_once_init(void)
{
}
}
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