Skip to content

Commit 10ebabc

Browse files
committed
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()
1 parent 73be875 commit 10ebabc

File tree

4 files changed

+36
-197
lines changed

4 files changed

+36
-197
lines changed

include/my_sys.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -690,12 +690,12 @@ int my_set_user(const char *user, struct passwd *user_info, myf MyFlags);
690690
extern int check_if_legal_filename(const char *path);
691691
extern int check_if_legal_tablename(const char *path);
692692

693-
#ifdef __WIN__
693+
#ifdef _WIN32
694694
extern my_bool is_filename_allowed(const char *name, size_t length,
695695
my_bool allow_current_dir);
696-
#else /* __WIN__ */
696+
#else /* _WIN32 */
697697
# define is_filename_allowed(name, length, allow_cwd) (TRUE)
698-
#endif /* __WIN__ */
698+
#endif /* _WIN32 */
699699

700700
#ifdef _WIN32
701701
/* Windows-only functions (CRT equivalents)*/
@@ -1045,7 +1045,7 @@ extern size_t escape_string_for_mysql(CHARSET_INFO *charset_info,
10451045
char *to, size_t to_length,
10461046
const char *from, size_t length);
10471047
extern char *get_tty_password(const char *opt_message);
1048-
#ifdef __WIN__
1048+
#ifdef _WIN32
10491049
#define BACKSLASH_MBTAIL
10501050
/* File system character set */
10511051
extern CHARSET_INFO *fs_character_set(void);
@@ -1058,8 +1058,7 @@ extern void thd_increment_bytes_sent(void *thd, size_t length);
10581058
extern void thd_increment_bytes_received(void *thd, size_t length);
10591059
extern void thd_increment_net_big_packet_count(void *thd, size_t length);
10601060

1061-
#ifdef __WIN__
1062-
extern my_bool have_tcpip; /* Is set if tcpip is used */
1061+
#ifdef _WIN32
10631062

10641063
/* implemented in my_windac.c */
10651064

mysys/my_init.c

Lines changed: 16 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,13 @@
2222
#include <m_ctype.h>
2323
#include <signal.h>
2424
#include <mysql/psi/mysql_stage.h>
25-
#ifdef __WIN__
25+
#ifdef _WIN32
2626
#ifdef _MSC_VER
2727
#include <locale.h>
2828
#include <crtdbg.h>
2929
/* WSAStartup needs winsock library*/
3030
#pragma comment(lib, "ws2_32")
3131
#endif
32-
my_bool have_tcpip=0;
3332
static void my_win_init(void);
3433
static my_bool win32_init_tcp_ip();
3534
#else
@@ -119,8 +118,9 @@ my_bool my_init(void)
119118
my_time_init();
120119
my_win_init();
121120
DBUG_PRINT("exit", ("home: '%s'", home_dir));
122-
#ifdef __WIN__
123-
win32_init_tcp_ip();
121+
#ifdef _WIN32
122+
if (win32_init_tcp_ip())
123+
DBUG_RETURN(1);
124124
#endif
125125
#ifdef CHECK_UNLIKELY
126126
init_my_likely();
@@ -218,7 +218,7 @@ Voluntary context switches %ld, Involuntary context switches %ld\n",
218218
rus.ru_msgsnd, rus.ru_msgrcv, rus.ru_nsignals,
219219
rus.ru_nvcsw, rus.ru_nivcsw);
220220
#endif
221-
#if defined(__WIN__) && defined(_MSC_VER)
221+
#if defined(_MSC_VER)
222222
_CrtSetReportMode( _CRT_WARN, _CRTDBG_MODE_FILE );
223223
_CrtSetReportFile( _CRT_WARN, _CRTDBG_FILE_STDERR );
224224
_CrtSetReportMode( _CRT_ERROR, _CRTDBG_MODE_FILE );
@@ -245,10 +245,9 @@ Voluntary context switches %ld, Involuntary context switches %ld\n",
245245
(FILE *) 0);
246246
#endif /* defined(SAFE_MUTEX) */
247247

248-
#ifdef __WIN__
249-
if (have_tcpip)
250-
WSACleanup();
251-
#endif /* __WIN__ */
248+
#ifdef _WIN32
249+
WSACleanup();
250+
#endif
252251

253252
/* At very last, delete mysys key, it is used everywhere including DBUG */
254253
pthread_key_delete(THR_KEY_mysys);
@@ -263,16 +262,14 @@ void my_debug_put_break_here(void)
263262
}
264263
#endif
265264

266-
#ifdef __WIN__
265+
#ifdef _WIN32
267266

268267

269268
/*
270269
my_parameter_handler
271270
272271
Invalid parameter handler we will use instead of the one "baked"
273-
into the CRT for MSC v8. This one just prints out what invalid
274-
parameter was encountered. By providing this routine, routines like
275-
lseek will return -1 when we expect them to instead of crash.
272+
into the CRT.
276273
*/
277274

278275
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,
311308
#pragma runtime_checks("", restore)
312309
#endif
313310

314-
/*
315-
Open HKEY_LOCAL_MACHINE\SOFTWARE\MySQL and set any strings found
316-
there as environment variables
317-
*/
318-
static void win_init_registry(void)
319-
{
320-
HKEY key_handle;
321-
322-
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, (LPCTSTR)"SOFTWARE\\MySQL",
323-
0, KEY_READ, &key_handle) == ERROR_SUCCESS)
324-
{
325-
LONG ret;
326-
DWORD index= 0;
327-
DWORD type;
328-
char key_name[256], key_data[1024];
329-
DWORD key_name_len= sizeof(key_name) - 1;
330-
DWORD key_data_len= sizeof(key_data) - 1;
331-
332-
while ((ret= RegEnumValue(key_handle, index++,
333-
key_name, &key_name_len,
334-
NULL, &type, (LPBYTE)&key_data,
335-
&key_data_len)) != ERROR_NO_MORE_ITEMS)
336-
{
337-
char env_string[sizeof(key_name) + sizeof(key_data) + 2];
338-
339-
if (ret == ERROR_MORE_DATA)
340-
{
341-
/* Registry value larger than 'key_data', skip it */
342-
DBUG_PRINT("error", ("Skipped registry value that was too large"));
343-
}
344-
else if (ret == ERROR_SUCCESS)
345-
{
346-
if (type == REG_SZ)
347-
{
348-
strxmov(env_string, key_name, "=", key_data, NullS);
349-
350-
/* variable for putenv must be allocated ! */
351-
putenv(strdup(env_string)) ;
352-
}
353-
}
354-
else
355-
{
356-
/* Unhandled error, break out of loop */
357-
break;
358-
}
359-
360-
key_name_len= sizeof(key_name) - 1;
361-
key_data_len= sizeof(key_data) - 1;
362-
}
363-
364-
RegCloseKey(key_handle);
365-
}
366-
}
367-
368311

369312
static void my_win_init(void)
370313
{
371314
DBUG_ENTER("my_win_init");
372315

373316
#if defined(_MSC_VER)
374-
#if _MSC_VER < 1300
375-
/*
376-
Clear the OS system variable TZ and avoid the 100% CPU usage
377-
Only for old versions of Visual C++
378-
*/
379-
_putenv("TZ=");
380-
#endif
381-
#if _MSC_VER >= 1400
382-
/* this is required to make crt functions return -1 appropriately */
383317
_set_invalid_parameter_handler(my_parameter_handler);
384318
#endif
385-
#endif
386319

387320
#ifdef __MSVC_RUNTIME_CHECKS
388321
/*
@@ -394,75 +327,22 @@ static void my_win_init(void)
394327

395328
_tzset();
396329

397-
win_init_registry();
398-
399330
DBUG_VOID_RETURN;
400331
}
401332

402333

403-
/*------------------------------------------------------------------
404-
Name: CheckForTcpip| Desc: checks if tcpip has been installed on system
405-
According to Microsoft Developers documentation the first registry
406-
entry should be enough to check if TCP/IP is installed, but as expected
407-
this doesn't work on all Win32 machines :(
408-
------------------------------------------------------------------*/
409-
410-
#define TCPIPKEY "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters"
411-
#define WINSOCK2KEY "SYSTEM\\CurrentControlSet\\Services\\Winsock2\\Parameters"
412-
#define WINSOCKKEY "SYSTEM\\CurrentControlSet\\Services\\Winsock\\Parameters"
413-
414-
static my_bool win32_have_tcpip(void)
415-
{
416-
HKEY hTcpipRegKey;
417-
if (RegOpenKeyEx ( HKEY_LOCAL_MACHINE, TCPIPKEY, 0, KEY_READ,
418-
&hTcpipRegKey) != ERROR_SUCCESS)
419-
{
420-
if (RegOpenKeyEx ( HKEY_LOCAL_MACHINE, WINSOCK2KEY, 0, KEY_READ,
421-
&hTcpipRegKey) != ERROR_SUCCESS)
422-
{
423-
if (RegOpenKeyEx ( HKEY_LOCAL_MACHINE, WINSOCKKEY, 0, KEY_READ,
424-
&hTcpipRegKey) != ERROR_SUCCESS)
425-
if (!getenv("HAVE_TCPIP") || have_tcpip) /* Provide a workaround */
426-
return (FALSE);
427-
}
428-
}
429-
RegCloseKey ( hTcpipRegKey);
430-
return (TRUE);
431-
}
432-
433-
434334
static my_bool win32_init_tcp_ip()
435335
{
436-
if (win32_have_tcpip())
336+
WORD wVersionRequested = MAKEWORD( 2, 2 );
337+
WSADATA wsaData;
338+
if (WSAStartup(wVersionRequested, &wsaData))
437339
{
438-
WORD wVersionRequested = MAKEWORD( 2, 2 );
439-
WSADATA wsaData;
440-
/* Be a good citizen: maybe another lib has already initialised
441-
sockets, so don't clobber them unless necessary */
442-
if (WSAStartup( wVersionRequested, &wsaData ))
443-
{
444-
/* Load failed, maybe because of previously loaded
445-
incompatible version; try again */
446-
WSACleanup( );
447-
if (!WSAStartup( wVersionRequested, &wsaData ))
448-
have_tcpip=1;
449-
}
450-
else
451-
{
452-
if (wsaData.wVersion != wVersionRequested)
453-
{
454-
/* Version is no good, try again */
455-
WSACleanup( );
456-
if (!WSAStartup( wVersionRequested, &wsaData ))
457-
have_tcpip=1;
458-
}
459-
else
460-
have_tcpip=1;
461-
}
340+
fprintf(stderr, "WSAStartup() failed with error: %d\n", WSAGetLastError());
341+
return 1;
462342
}
463343
return(0);
464344
}
465-
#endif /* __WIN__ */
345+
#endif /* _WIN32 */
466346

467347
PSI_stage_info stage_waiting_for_table_level_lock=
468348
{0, "Waiting for table level lock", 0};

0 commit comments

Comments
 (0)