Commit 10ebabc3 authored by Vladislav Vaintroub's avatar Vladislav Vaintroub

Windows related cleanups, remove old code.

- Do not scan registry to check if TCPIP is supported.
- Do not read registry under HKEY_LOCAL_MACHINE\SOFTWARE\MySQL anymore.
- Do not load threadpool function dynamically, it is available
since Win7.
- simplify win32_init_tcp_ip(), and return error of WSAStartup() fails.
- Correct comment in my_parameter_handler()
parent 73be875c
...@@ -690,12 +690,12 @@ int my_set_user(const char *user, struct passwd *user_info, myf MyFlags); ...@@ -690,12 +690,12 @@ int my_set_user(const char *user, struct passwd *user_info, myf MyFlags);
extern int check_if_legal_filename(const char *path); extern int check_if_legal_filename(const char *path);
extern int check_if_legal_tablename(const char *path); extern int check_if_legal_tablename(const char *path);
#ifdef __WIN__ #ifdef _WIN32
extern my_bool is_filename_allowed(const char *name, size_t length, extern my_bool is_filename_allowed(const char *name, size_t length,
my_bool allow_current_dir); my_bool allow_current_dir);
#else /* __WIN__ */ #else /* _WIN32 */
# define is_filename_allowed(name, length, allow_cwd) (TRUE) # define is_filename_allowed(name, length, allow_cwd) (TRUE)
#endif /* __WIN__ */ #endif /* _WIN32 */
#ifdef _WIN32 #ifdef _WIN32
/* Windows-only functions (CRT equivalents)*/ /* Windows-only functions (CRT equivalents)*/
...@@ -1045,7 +1045,7 @@ extern size_t escape_string_for_mysql(CHARSET_INFO *charset_info, ...@@ -1045,7 +1045,7 @@ extern size_t escape_string_for_mysql(CHARSET_INFO *charset_info,
char *to, size_t to_length, char *to, size_t to_length,
const char *from, size_t length); const char *from, size_t length);
extern char *get_tty_password(const char *opt_message); extern char *get_tty_password(const char *opt_message);
#ifdef __WIN__ #ifdef _WIN32
#define BACKSLASH_MBTAIL #define BACKSLASH_MBTAIL
/* File system character set */ /* File system character set */
extern CHARSET_INFO *fs_character_set(void); extern CHARSET_INFO *fs_character_set(void);
...@@ -1058,8 +1058,7 @@ extern void thd_increment_bytes_sent(void *thd, size_t length); ...@@ -1058,8 +1058,7 @@ extern void thd_increment_bytes_sent(void *thd, size_t length);
extern void thd_increment_bytes_received(void *thd, size_t length); extern void thd_increment_bytes_received(void *thd, size_t length);
extern void thd_increment_net_big_packet_count(void *thd, size_t length); extern void thd_increment_net_big_packet_count(void *thd, size_t length);
#ifdef __WIN__ #ifdef _WIN32
extern my_bool have_tcpip; /* Is set if tcpip is used */
/* implemented in my_windac.c */ /* implemented in my_windac.c */
......
...@@ -22,14 +22,13 @@ ...@@ -22,14 +22,13 @@
#include <m_ctype.h> #include <m_ctype.h>
#include <signal.h> #include <signal.h>
#include <mysql/psi/mysql_stage.h> #include <mysql/psi/mysql_stage.h>
#ifdef __WIN__ #ifdef _WIN32
#ifdef _MSC_VER #ifdef _MSC_VER
#include <locale.h> #include <locale.h>
#include <crtdbg.h> #include <crtdbg.h>
/* WSAStartup needs winsock library*/ /* WSAStartup needs winsock library*/
#pragma comment(lib, "ws2_32") #pragma comment(lib, "ws2_32")
#endif #endif
my_bool have_tcpip=0;
static void my_win_init(void); static void my_win_init(void);
static my_bool win32_init_tcp_ip(); static my_bool win32_init_tcp_ip();
#else #else
...@@ -119,8 +118,9 @@ my_bool my_init(void) ...@@ -119,8 +118,9 @@ my_bool my_init(void)
my_time_init(); my_time_init();
my_win_init(); my_win_init();
DBUG_PRINT("exit", ("home: '%s'", home_dir)); DBUG_PRINT("exit", ("home: '%s'", home_dir));
#ifdef __WIN__ #ifdef _WIN32
win32_init_tcp_ip(); if (win32_init_tcp_ip())
DBUG_RETURN(1);
#endif #endif
#ifdef CHECK_UNLIKELY #ifdef CHECK_UNLIKELY
init_my_likely(); init_my_likely();
...@@ -218,7 +218,7 @@ Voluntary context switches %ld, Involuntary context switches %ld\n", ...@@ -218,7 +218,7 @@ Voluntary context switches %ld, Involuntary context switches %ld\n",
rus.ru_msgsnd, rus.ru_msgrcv, rus.ru_nsignals, rus.ru_msgsnd, rus.ru_msgrcv, rus.ru_nsignals,
rus.ru_nvcsw, rus.ru_nivcsw); rus.ru_nvcsw, rus.ru_nivcsw);
#endif #endif
#if defined(__WIN__) && defined(_MSC_VER) #if defined(_MSC_VER)
_CrtSetReportMode( _CRT_WARN, _CRTDBG_MODE_FILE ); _CrtSetReportMode( _CRT_WARN, _CRTDBG_MODE_FILE );
_CrtSetReportFile( _CRT_WARN, _CRTDBG_FILE_STDERR ); _CrtSetReportFile( _CRT_WARN, _CRTDBG_FILE_STDERR );
_CrtSetReportMode( _CRT_ERROR, _CRTDBG_MODE_FILE ); _CrtSetReportMode( _CRT_ERROR, _CRTDBG_MODE_FILE );
...@@ -245,10 +245,9 @@ Voluntary context switches %ld, Involuntary context switches %ld\n", ...@@ -245,10 +245,9 @@ Voluntary context switches %ld, Involuntary context switches %ld\n",
(FILE *) 0); (FILE *) 0);
#endif /* defined(SAFE_MUTEX) */ #endif /* defined(SAFE_MUTEX) */
#ifdef __WIN__ #ifdef _WIN32
if (have_tcpip) WSACleanup();
WSACleanup(); #endif
#endif /* __WIN__ */
/* At very last, delete mysys key, it is used everywhere including DBUG */ /* At very last, delete mysys key, it is used everywhere including DBUG */
pthread_key_delete(THR_KEY_mysys); pthread_key_delete(THR_KEY_mysys);
...@@ -263,16 +262,14 @@ void my_debug_put_break_here(void) ...@@ -263,16 +262,14 @@ void my_debug_put_break_here(void)
} }
#endif #endif
#ifdef __WIN__ #ifdef _WIN32
/* /*
my_parameter_handler my_parameter_handler
Invalid parameter handler we will use instead of the one "baked" Invalid parameter handler we will use instead of the one "baked"
into the CRT for MSC v8. This one just prints out what invalid into the CRT.
parameter was encountered. By providing this routine, routines like
lseek will return -1 when we expect them to instead of crash.
*/ */
void my_parameter_handler(const wchar_t * expression, const wchar_t * function, void my_parameter_handler(const wchar_t * expression, const wchar_t * function,
...@@ -311,78 +308,14 @@ int handle_rtc_failure(int err_type, const char *file, int line, ...@@ -311,78 +308,14 @@ int handle_rtc_failure(int err_type, const char *file, int line,
#pragma runtime_checks("", restore) #pragma runtime_checks("", restore)
#endif #endif
/*
Open HKEY_LOCAL_MACHINE\SOFTWARE\MySQL and set any strings found
there as environment variables
*/
static void win_init_registry(void)
{
HKEY key_handle;
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, (LPCTSTR)"SOFTWARE\\MySQL",
0, KEY_READ, &key_handle) == ERROR_SUCCESS)
{
LONG ret;
DWORD index= 0;
DWORD type;
char key_name[256], key_data[1024];
DWORD key_name_len= sizeof(key_name) - 1;
DWORD key_data_len= sizeof(key_data) - 1;
while ((ret= RegEnumValue(key_handle, index++,
key_name, &key_name_len,
NULL, &type, (LPBYTE)&key_data,
&key_data_len)) != ERROR_NO_MORE_ITEMS)
{
char env_string[sizeof(key_name) + sizeof(key_data) + 2];
if (ret == ERROR_MORE_DATA)
{
/* Registry value larger than 'key_data', skip it */
DBUG_PRINT("error", ("Skipped registry value that was too large"));
}
else if (ret == ERROR_SUCCESS)
{
if (type == REG_SZ)
{
strxmov(env_string, key_name, "=", key_data, NullS);
/* variable for putenv must be allocated ! */
putenv(strdup(env_string)) ;
}
}
else
{
/* Unhandled error, break out of loop */
break;
}
key_name_len= sizeof(key_name) - 1;
key_data_len= sizeof(key_data) - 1;
}
RegCloseKey(key_handle);
}
}
static void my_win_init(void) static void my_win_init(void)
{ {
DBUG_ENTER("my_win_init"); DBUG_ENTER("my_win_init");
#if defined(_MSC_VER) #if defined(_MSC_VER)
#if _MSC_VER < 1300
/*
Clear the OS system variable TZ and avoid the 100% CPU usage
Only for old versions of Visual C++
*/
_putenv("TZ=");
#endif
#if _MSC_VER >= 1400
/* this is required to make crt functions return -1 appropriately */
_set_invalid_parameter_handler(my_parameter_handler); _set_invalid_parameter_handler(my_parameter_handler);
#endif #endif
#endif
#ifdef __MSVC_RUNTIME_CHECKS #ifdef __MSVC_RUNTIME_CHECKS
/* /*
...@@ -394,75 +327,22 @@ static void my_win_init(void) ...@@ -394,75 +327,22 @@ static void my_win_init(void)
_tzset(); _tzset();
win_init_registry();
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
/*------------------------------------------------------------------
Name: CheckForTcpip| Desc: checks if tcpip has been installed on system
According to Microsoft Developers documentation the first registry
entry should be enough to check if TCP/IP is installed, but as expected
this doesn't work on all Win32 machines :(
------------------------------------------------------------------*/
#define TCPIPKEY "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters"
#define WINSOCK2KEY "SYSTEM\\CurrentControlSet\\Services\\Winsock2\\Parameters"
#define WINSOCKKEY "SYSTEM\\CurrentControlSet\\Services\\Winsock\\Parameters"
static my_bool win32_have_tcpip(void)
{
HKEY hTcpipRegKey;
if (RegOpenKeyEx ( HKEY_LOCAL_MACHINE, TCPIPKEY, 0, KEY_READ,
&hTcpipRegKey) != ERROR_SUCCESS)
{
if (RegOpenKeyEx ( HKEY_LOCAL_MACHINE, WINSOCK2KEY, 0, KEY_READ,
&hTcpipRegKey) != ERROR_SUCCESS)
{
if (RegOpenKeyEx ( HKEY_LOCAL_MACHINE, WINSOCKKEY, 0, KEY_READ,
&hTcpipRegKey) != ERROR_SUCCESS)
if (!getenv("HAVE_TCPIP") || have_tcpip) /* Provide a workaround */
return (FALSE);
}
}
RegCloseKey ( hTcpipRegKey);
return (TRUE);
}
static my_bool win32_init_tcp_ip() static my_bool win32_init_tcp_ip()
{ {
if (win32_have_tcpip()) WORD wVersionRequested = MAKEWORD( 2, 2 );
WSADATA wsaData;
if (WSAStartup(wVersionRequested, &wsaData))
{ {
WORD wVersionRequested = MAKEWORD( 2, 2 ); fprintf(stderr, "WSAStartup() failed with error: %d\n", WSAGetLastError());
WSADATA wsaData; return 1;
/* Be a good citizen: maybe another lib has already initialised
sockets, so don't clobber them unless necessary */
if (WSAStartup( wVersionRequested, &wsaData ))
{
/* Load failed, maybe because of previously loaded
incompatible version; try again */
WSACleanup( );
if (!WSAStartup( wVersionRequested, &wsaData ))
have_tcpip=1;
}
else
{
if (wsaData.wVersion != wVersionRequested)
{
/* Version is no good, try again */
WSACleanup( );
if (!WSAStartup( wVersionRequested, &wsaData ))
have_tcpip=1;
}
else
have_tcpip=1;
}
} }
return(0); return(0);
} }
#endif /* __WIN__ */ #endif /* _WIN32 */
PSI_stage_info stage_waiting_for_table_level_lock= PSI_stage_info stage_waiting_for_table_level_lock=
{0, "Waiting for table level lock", 0}; {0, "Waiting for table level lock", 0};
......
...@@ -69,9 +69,9 @@ my_bool net_flush(NET *net); ...@@ -69,9 +69,9 @@ my_bool net_flush(NET *net);
#include "errmsg.h" #include "errmsg.h"
#include <violite.h> #include <violite.h>
#if !defined(__WIN__) #if !defined(_WIN32)
#include <my_pthread.h> /* because of signal() */ #include <my_pthread.h> /* because of signal() */
#endif /* !defined(__WIN__) */ #endif /* !defined(_WIN32) */
#include <sys/stat.h> #include <sys/stat.h>
#include <signal.h> #include <signal.h>
...@@ -81,29 +81,20 @@ my_bool net_flush(NET *net); ...@@ -81,29 +81,20 @@ my_bool net_flush(NET *net);
#include <pwd.h> #include <pwd.h>
#endif #endif
#if !defined(__WIN__) #if !defined(_WIN32)
#ifdef HAVE_SELECT_H #ifdef HAVE_SELECT_H
# include <select.h> # include <select.h>
#endif #endif
#ifdef HAVE_SYS_SELECT_H #ifdef HAVE_SYS_SELECT_H
#include <sys/select.h> #include <sys/select.h>
#endif #endif
#endif /* !defined(__WIN__) */ #endif /* !defined(_WIN32) */
#ifdef HAVE_SYS_UN_H #ifdef HAVE_SYS_UN_H
# include <sys/un.h> # include <sys/un.h>
#endif #endif
#ifndef _WIN32
#include <errno.h>
#define SOCKET_ERROR -1
#define INVALID_SOCKET -1
#endif
#ifdef __WIN__
#define CONNECT_TIMEOUT 20
#else
#define CONNECT_TIMEOUT 0 #define CONNECT_TIMEOUT 0
#endif
#include "client_settings.h" #include "client_settings.h"
#include <ssl_compat.h> #include <ssl_compat.h>
...@@ -252,7 +243,7 @@ void set_mysql_extended_error(MYSQL *mysql, int errcode, ...@@ -252,7 +243,7 @@ void set_mysql_extended_error(MYSQL *mysql, int errcode,
Create a named pipe connection Create a named pipe connection
*/ */
#ifdef __WIN__ #ifdef _WIN32
HANDLE create_named_pipe(MYSQL *mysql, uint connect_timeout, char **arg_host, HANDLE create_named_pipe(MYSQL *mysql, uint connect_timeout, char **arg_host,
char **arg_unix_socket) char **arg_unix_socket)
...@@ -1692,7 +1683,7 @@ typedef struct str2str_st ...@@ -1692,7 +1683,7 @@ typedef struct str2str_st
const MY_CSET_OS_NAME charsets[]= const MY_CSET_OS_NAME charsets[]=
{ {
#ifdef __WIN__ #ifdef _WIN32
{"cp437", "cp850", my_cs_approx}, {"cp437", "cp850", my_cs_approx},
{"cp850", "cp850", my_cs_exact}, {"cp850", "cp850", my_cs_exact},
{"cp852", "cp852", my_cs_exact}, {"cp852", "cp852", my_cs_exact},
...@@ -1878,7 +1869,7 @@ my_os_charset_to_mysql_charset(const char *csname) ...@@ -1878,7 +1869,7 @@ my_os_charset_to_mysql_charset(const char *csname)
} }
#ifndef __WIN__ #ifndef _WIN32
#include <stdlib.h> /* for getenv() */ #include <stdlib.h> /* for getenv() */
#ifdef HAVE_LANGINFO_H #ifdef HAVE_LANGINFO_H
#include <langinfo.h> #include <langinfo.h>
...@@ -1886,7 +1877,7 @@ my_os_charset_to_mysql_charset(const char *csname) ...@@ -1886,7 +1877,7 @@ my_os_charset_to_mysql_charset(const char *csname)
#ifdef HAVE_LOCALE_H #ifdef HAVE_LOCALE_H
#include <locale.h> #include <locale.h>
#endif #endif
#endif /* __WIN__ */ #endif /* _WIN32 */
static int static int
...@@ -1894,7 +1885,7 @@ mysql_autodetect_character_set(MYSQL *mysql) ...@@ -1894,7 +1885,7 @@ mysql_autodetect_character_set(MYSQL *mysql)
{ {
const char *csname= MYSQL_DEFAULT_CHARSET_NAME; const char *csname= MYSQL_DEFAULT_CHARSET_NAME;
#ifdef __WIN__ #ifdef _WIN32
char cpbuf[64]; char cpbuf[64];
{ {
UINT cp= GetConsoleCP(); UINT cp= GetConsoleCP();
...@@ -2836,14 +2827,10 @@ set_connect_attributes(MYSQL *mysql, char *buff, size_t buf_len) ...@@ -2836,14 +2827,10 @@ set_connect_attributes(MYSQL *mysql, char *buff, size_t buf_len)
"_platform", MACHINE_TYPE); "_platform", MACHINE_TYPE);
rc+= mysql_options4(mysql, MYSQL_OPT_CONNECT_ATTR_ADD, rc+= mysql_options4(mysql, MYSQL_OPT_CONNECT_ATTR_ADD,
"_server_host", mysql->host); "_server_host", mysql->host);
#ifdef __WIN__
snprintf(buff, buf_len, "%lu", (ulong) GetCurrentProcessId());
#else
snprintf(buff, buf_len, "%lu", (ulong) getpid()); snprintf(buff, buf_len, "%lu", (ulong) getpid());
#endif
rc+= mysql_options4(mysql, MYSQL_OPT_CONNECT_ATTR_ADD, "_pid", buff); rc+= mysql_options4(mysql, MYSQL_OPT_CONNECT_ATTR_ADD, "_pid", buff);
#ifdef __WIN__ #ifdef _WIN32
snprintf(buff, buf_len, "%lu", (ulong) GetCurrentThreadId()); snprintf(buff, buf_len, "%lu", (ulong) GetCurrentThreadId());
rc+= mysql_options4(mysql, MYSQL_OPT_CONNECT_ATTR_ADD, "_thread", buff); rc+= mysql_options4(mysql, MYSQL_OPT_CONNECT_ATTR_ADD, "_thread", buff);
#endif #endif
...@@ -2864,7 +2851,7 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,const char *host, const char *user, ...@@ -2864,7 +2851,7 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,const char *host, const char *user,
const char *scramble_plugin; const char *scramble_plugin;
ulong pkt_length; ulong pkt_length;
NET *net= &mysql->net; NET *net= &mysql->net;
#ifdef __WIN__ #ifdef _WIN32
HANDLE hPipe=INVALID_HANDLE_VALUE; HANDLE hPipe=INVALID_HANDLE_VALUE;
#endif #endif
#ifdef HAVE_SYS_UN_H #ifdef HAVE_SYS_UN_H
...@@ -2986,21 +2973,19 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,const char *host, const char *user, ...@@ -2986,21 +2973,19 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,const char *host, const char *user,
} }
mysql->options.protocol=MYSQL_PROTOCOL_SOCKET; mysql->options.protocol=MYSQL_PROTOCOL_SOCKET;
} }
#elif defined(__WIN__) #elif defined(_WIN32)
if (!net->vio && if (!net->vio &&
(mysql->options.protocol == MYSQL_PROTOCOL_PIPE || (mysql->options.protocol == MYSQL_PROTOCOL_PIPE ||
(host && !strcmp(host,LOCAL_HOST_NAMEDPIPE)) || (host && !strcmp(host,LOCAL_HOST_NAMEDPIPE))))
(! have_tcpip && (unix_socket || !host ))))
{ {
if ((hPipe= create_named_pipe(mysql, mysql->options.connect_timeout, if ((hPipe= create_named_pipe(mysql, mysql->options.connect_timeout,
(char**) &host, (char**) &unix_socket)) == (char**) &host, (char**) &unix_socket)) ==
INVALID_HANDLE_VALUE) INVALID_HANDLE_VALUE)
{ {
DBUG_PRINT("error", DBUG_PRINT("error",
("host: '%s' socket: '%s' have_tcpip: %d", ("host: '%s' socket: '%s'",
host ? host : "<null>", host ? host : "<null>",
unix_socket ? unix_socket : "<null>", unix_socket ? unix_socket : "<null>"));
(int) have_tcpip));
if (mysql->options.protocol == MYSQL_PROTOCOL_PIPE || if (mysql->options.protocol == MYSQL_PROTOCOL_PIPE ||
(host && !strcmp(host,LOCAL_HOST_NAMEDPIPE)) || (host && !strcmp(host,LOCAL_HOST_NAMEDPIPE)) ||
(unix_socket && !strcmp(unix_socket,MYSQL_NAMEDPIPE))) (unix_socket && !strcmp(unix_socket,MYSQL_NAMEDPIPE)))
......
...@@ -31,31 +31,6 @@ ...@@ -31,31 +31,6 @@
#include <threadpool.h> #include <threadpool.h>
#include <windows.h> #include <windows.h>
/*
WEAK_SYMBOL(return_type, function_name, argument_type1,..,argument_typeN)
Declare and load function pointer from kernel32. The name of the static
variable that holds the function pointer is my_<original function name>
This should be combined with
#define <original function name> my_<original function name>
so that one could use Widows APIs transparently, without worrying whether
they are present in a particular version or not.
Of course, prior to use of any function there should be a check for correct
Windows version, or check whether function pointer is not NULL.
*/
#define WEAK_SYMBOL(return_type, function, ...) \
typedef return_type (WINAPI *pFN_##function)(__VA_ARGS__); \
static pFN_##function my_##function = (pFN_##function) \
(GetProcAddress(GetModuleHandle("kernel32"),#function))
WEAK_SYMBOL(BOOL, SetThreadpoolStackInformation, PTP_POOL,
PTP_POOL_STACK_INFORMATION);
#define SetThreadpoolStackInformation my_SetThreadpoolStackInformation
/* Log a warning */ /* Log a warning */
static void tp_log_warning(const char *msg, const char *fct) static void tp_log_warning(const char *msg, const char *fct)
{ {
......
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