diff options
-rw-r--r-- | include/my_sys.h | 11 | ||||
-rw-r--r-- | mysys/my_init.c | 152 | ||||
-rw-r--r-- | sql-common/client.c | 45 | ||||
-rw-r--r-- | sql/threadpool_win.cc | 25 |
4 files changed, 36 insertions, 197 deletions
diff --git a/include/my_sys.h b/include/my_sys.h index 09d89607474..17cf1a1b53f 100644 --- a/include/my_sys.h +++ b/include/my_sys.h @@ -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_tablename(const char *path); -#ifdef __WIN__ +#ifdef _WIN32 extern my_bool is_filename_allowed(const char *name, size_t length, my_bool allow_current_dir); -#else /* __WIN__ */ +#else /* _WIN32 */ # define is_filename_allowed(name, length, allow_cwd) (TRUE) -#endif /* __WIN__ */ +#endif /* _WIN32 */ #ifdef _WIN32 /* Windows-only functions (CRT equivalents)*/ @@ -1045,7 +1045,7 @@ extern size_t escape_string_for_mysql(CHARSET_INFO *charset_info, char *to, size_t to_length, const char *from, size_t length); extern char *get_tty_password(const char *opt_message); -#ifdef __WIN__ +#ifdef _WIN32 #define BACKSLASH_MBTAIL /* File system character set */ extern CHARSET_INFO *fs_character_set(void); @@ -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_net_big_packet_count(void *thd, size_t length); -#ifdef __WIN__ -extern my_bool have_tcpip; /* Is set if tcpip is used */ +#ifdef _WIN32 /* implemented in my_windac.c */ diff --git a/mysys/my_init.c b/mysys/my_init.c index d8fb2003052..fdde04be084 100644 --- a/mysys/my_init.c +++ b/mysys/my_init.c @@ -22,14 +22,13 @@ #include <m_ctype.h> #include <signal.h> #include <mysql/psi/mysql_stage.h> -#ifdef __WIN__ +#ifdef _WIN32 #ifdef _MSC_VER #include <locale.h> #include <crtdbg.h> /* WSAStartup needs winsock library*/ #pragma comment(lib, "ws2_32") #endif -my_bool have_tcpip=0; static void my_win_init(void); static my_bool win32_init_tcp_ip(); #else @@ -119,8 +118,9 @@ my_bool my_init(void) my_time_init(); my_win_init(); DBUG_PRINT("exit", ("home: '%s'", home_dir)); -#ifdef __WIN__ - win32_init_tcp_ip(); +#ifdef _WIN32 + if (win32_init_tcp_ip()) + DBUG_RETURN(1); #endif #ifdef CHECK_UNLIKELY init_my_likely(); @@ -218,7 +218,7 @@ Voluntary context switches %ld, Involuntary context switches %ld\n", rus.ru_msgsnd, rus.ru_msgrcv, rus.ru_nsignals, rus.ru_nvcsw, rus.ru_nivcsw); #endif -#if defined(__WIN__) && defined(_MSC_VER) +#if defined(_MSC_VER) _CrtSetReportMode( _CRT_WARN, _CRTDBG_MODE_FILE ); _CrtSetReportFile( _CRT_WARN, _CRTDBG_FILE_STDERR ); _CrtSetReportMode( _CRT_ERROR, _CRTDBG_MODE_FILE ); @@ -245,10 +245,9 @@ Voluntary context switches %ld, Involuntary context switches %ld\n", (FILE *) 0); #endif /* defined(SAFE_MUTEX) */ -#ifdef __WIN__ - if (have_tcpip) - WSACleanup(); -#endif /* __WIN__ */ +#ifdef _WIN32 + WSACleanup(); +#endif /* At very last, delete mysys key, it is used everywhere including DBUG */ pthread_key_delete(THR_KEY_mysys); @@ -263,16 +262,14 @@ void my_debug_put_break_here(void) } #endif -#ifdef __WIN__ +#ifdef _WIN32 /* my_parameter_handler Invalid parameter handler we will use instead of the one "baked" - into the CRT for MSC v8. This one just prints out what invalid - parameter was encountered. By providing this routine, routines like - lseek will return -1 when we expect them to instead of crash. + into the CRT. */ 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, #pragma runtime_checks("", restore) #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) { DBUG_ENTER("my_win_init"); #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); #endif -#endif #ifdef __MSVC_RUNTIME_CHECKS /* @@ -394,75 +327,22 @@ static void my_win_init(void) _tzset(); - win_init_registry(); - 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() { - if (win32_have_tcpip()) + WORD wVersionRequested = MAKEWORD( 2, 2 ); + WSADATA wsaData; + if (WSAStartup(wVersionRequested, &wsaData)) { - WORD wVersionRequested = MAKEWORD( 2, 2 ); - WSADATA wsaData; - /* 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; - } + fprintf(stderr, "WSAStartup() failed with error: %d\n", WSAGetLastError()); + return 1; } return(0); } -#endif /* __WIN__ */ +#endif /* _WIN32 */ PSI_stage_info stage_waiting_for_table_level_lock= {0, "Waiting for table level lock", 0}; diff --git a/sql-common/client.c b/sql-common/client.c index 00d3464167a..ae657023772 100644 --- a/sql-common/client.c +++ b/sql-common/client.c @@ -69,9 +69,9 @@ my_bool net_flush(NET *net); #include "errmsg.h" #include <violite.h> -#if !defined(__WIN__) +#if !defined(_WIN32) #include <my_pthread.h> /* because of signal() */ -#endif /* !defined(__WIN__) */ +#endif /* !defined(_WIN32) */ #include <sys/stat.h> #include <signal.h> @@ -81,29 +81,20 @@ my_bool net_flush(NET *net); #include <pwd.h> #endif -#if !defined(__WIN__) +#if !defined(_WIN32) #ifdef HAVE_SELECT_H # include <select.h> #endif #ifdef HAVE_SYS_SELECT_H #include <sys/select.h> #endif -#endif /* !defined(__WIN__) */ +#endif /* !defined(_WIN32) */ #ifdef HAVE_SYS_UN_H # include <sys/un.h> #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 -#endif #include "client_settings.h" #include <ssl_compat.h> @@ -252,7 +243,7 @@ void set_mysql_extended_error(MYSQL *mysql, int errcode, Create a named pipe connection */ -#ifdef __WIN__ +#ifdef _WIN32 HANDLE create_named_pipe(MYSQL *mysql, uint connect_timeout, char **arg_host, char **arg_unix_socket) @@ -1692,7 +1683,7 @@ typedef struct str2str_st const MY_CSET_OS_NAME charsets[]= { -#ifdef __WIN__ +#ifdef _WIN32 {"cp437", "cp850", my_cs_approx}, {"cp850", "cp850", my_cs_exact}, {"cp852", "cp852", my_cs_exact}, @@ -1878,7 +1869,7 @@ def: } -#ifndef __WIN__ +#ifndef _WIN32 #include <stdlib.h> /* for getenv() */ #ifdef HAVE_LANGINFO_H #include <langinfo.h> @@ -1886,7 +1877,7 @@ def: #ifdef HAVE_LOCALE_H #include <locale.h> #endif -#endif /* __WIN__ */ +#endif /* _WIN32 */ static int @@ -1894,7 +1885,7 @@ mysql_autodetect_character_set(MYSQL *mysql) { const char *csname= MYSQL_DEFAULT_CHARSET_NAME; -#ifdef __WIN__ +#ifdef _WIN32 char cpbuf[64]; { UINT cp= GetConsoleCP(); @@ -2836,14 +2827,10 @@ set_connect_attributes(MYSQL *mysql, char *buff, size_t buf_len) "_platform", MACHINE_TYPE); rc+= mysql_options4(mysql, MYSQL_OPT_CONNECT_ATTR_ADD, "_server_host", mysql->host); -#ifdef __WIN__ - snprintf(buff, buf_len, "%lu", (ulong) GetCurrentProcessId()); -#else snprintf(buff, buf_len, "%lu", (ulong) getpid()); -#endif rc+= mysql_options4(mysql, MYSQL_OPT_CONNECT_ATTR_ADD, "_pid", buff); -#ifdef __WIN__ +#ifdef _WIN32 snprintf(buff, buf_len, "%lu", (ulong) GetCurrentThreadId()); rc+= mysql_options4(mysql, MYSQL_OPT_CONNECT_ATTR_ADD, "_thread", buff); #endif @@ -2864,7 +2851,7 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,const char *host, const char *user, const char *scramble_plugin; ulong pkt_length; NET *net= &mysql->net; -#ifdef __WIN__ +#ifdef _WIN32 HANDLE hPipe=INVALID_HANDLE_VALUE; #endif #ifdef HAVE_SYS_UN_H @@ -2986,21 +2973,19 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,const char *host, const char *user, } mysql->options.protocol=MYSQL_PROTOCOL_SOCKET; } -#elif defined(__WIN__) +#elif defined(_WIN32) if (!net->vio && (mysql->options.protocol == MYSQL_PROTOCOL_PIPE || - (host && !strcmp(host,LOCAL_HOST_NAMEDPIPE)) || - (! have_tcpip && (unix_socket || !host )))) + (host && !strcmp(host,LOCAL_HOST_NAMEDPIPE)))) { if ((hPipe= create_named_pipe(mysql, mysql->options.connect_timeout, (char**) &host, (char**) &unix_socket)) == INVALID_HANDLE_VALUE) { DBUG_PRINT("error", - ("host: '%s' socket: '%s' have_tcpip: %d", + ("host: '%s' socket: '%s'", host ? host : "<null>", - unix_socket ? unix_socket : "<null>", - (int) have_tcpip)); + unix_socket ? unix_socket : "<null>")); if (mysql->options.protocol == MYSQL_PROTOCOL_PIPE || (host && !strcmp(host,LOCAL_HOST_NAMEDPIPE)) || (unix_socket && !strcmp(unix_socket,MYSQL_NAMEDPIPE))) diff --git a/sql/threadpool_win.cc b/sql/threadpool_win.cc index 2751d8baeb0..15047a6dbfa 100644 --- a/sql/threadpool_win.cc +++ b/sql/threadpool_win.cc @@ -31,31 +31,6 @@ #include <threadpool.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 */ static void tp_log_warning(const char *msg, const char *fct) { |