From: Date: September 29 2008 7:48pm Subject: bzr push into mysql-6.0-falcon-team branch (vvaintroub:2841 to 2842) Bug#33031 Bug#37226 List-Archive: http://lists.mysql.com/commits/54683 X-Bug: 33031,37226 Message-Id: <200809291748.m8THmpqJ000949@mail.mysql.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 2842 Vladislav Vaintroub 2008-09-29 Bug#37226 - Explicit call of my_thread_init() on Windows for every new thread. Bug#33031 - app linked to libmysql.lib crash if run as service in vista under localsystem. This patch completely removes DllMain() from the libmysql.dll in 6.0 eliminating explicit my_thread_init()/WSAStartup() during dll load or thread attach. This patch is slightly different from what is done in 5.0/5.1. The difference is that there is no way that to reactivate DllMain() code (in 5.x it is possible with LIBMYSQL_DLLINIT environment variable) removed: libmysql/dll.c modified: libmysql/CMakeLists.txt libmysql/Makefile.am 2841 Hakan Kuecuekyilmaz 2008-09-29 [merge] Merge modified: configure.in === modified file 'libmysql/CMakeLists.txt' --- a/libmysql/CMakeLists.txt 2008-08-26 18:57:58 +0000 +++ b/libmysql/CMakeLists.txt 2008-09-29 17:47:27 +0000 @@ -119,7 +119,7 @@ ADD_LIBRARY(mysqlclient_notls STATIC ${C ADD_DEPENDENCIES(mysqlclient_notls GenError) TARGET_LINK_LIBRARIES(mysqlclient_notls) -ADD_LIBRARY(libmysql SHARED ${CLIENT_SOURCES} dll.c libmysql.def) +ADD_LIBRARY(libmysql SHARED ${CLIENT_SOURCES} libmysql.def) IF(WIN32) SET_TARGET_PROPERTIES(libmysql mysqlclient PROPERTIES COMPILE_FLAGS "-DUSE_TLS") ENDIF(WIN32) === modified file 'libmysql/Makefile.am' --- a/libmysql/Makefile.am 2007-11-22 11:39:07 +0000 +++ b/libmysql/Makefile.am 2008-09-29 17:47:27 +0000 @@ -31,7 +31,7 @@ include $(srcdir)/Makefile.shared libmysqlclient_la_SOURCES = $(target_sources) libmysqlclient_la_LIBADD = $(target_libadd) $(yassl_las) libmysqlclient_la_LDFLAGS = $(target_ldflags) -EXTRA_DIST = Makefile.shared libmysql.def dll.c CMakeLists.txt +EXTRA_DIST = Makefile.shared libmysql.def CMakeLists.txt noinst_HEADERS = client_settings.h link_sources: === removed file 'libmysql/dll.c' --- a/libmysql/dll.c 2008-09-01 22:30:06 +0000 +++ b/libmysql/dll.c 1970-01-01 00:00:00 +0000 @@ -1,125 +0,0 @@ -/* Copyright (C) 2000-2004 MySQL AB - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation. - - There are special exceptions to the terms and conditions of the GPL as it - is applied to this software. View the full text of the exception in file - EXCEPTIONS-CLIENT in the directory of this software distribution. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ - -/* -** Handling initialization of the dll library -*/ - -#include -#include -#include - -static my_bool libmysql_inited=0; - -void libmysql_init(void) -{ - if (libmysql_inited) - return; - libmysql_inited=1; - my_init(); - { - DBUG_ENTER("libmysql_init"); -#ifdef LOG_ALL - DBUG_PUSH("d:t:S:O,c::\\tmp\\libmysql.log"); -#else - if (getenv("LIBMYSQL_LOG") != NULL) - DBUG_PUSH(getenv("LIBMYSQL_LOG")); -#endif - DBUG_VOID_RETURN; - } -} - -#ifdef __WIN__ - -static int inited=0,threads=0; -HINSTANCE NEAR s_hModule; /* Saved module handle */ -DWORD main_thread; - -BOOL APIENTRY LibMain(HANDLE hInst,DWORD ul_reason_being_called, - LPVOID lpReserved) -{ - switch (ul_reason_being_called) { - case DLL_PROCESS_ATTACH: /* case of libentry call in win 3.x */ - if (!inited++) - { - s_hModule=hInst; - libmysql_init(); - main_thread=GetCurrentThreadId(); - } - break; - case DLL_THREAD_ATTACH: - threads++; - my_thread_init(); - break; - case DLL_PROCESS_DETACH: /* case of wep call in win 3.x */ - if (!--inited) /* Safety */ - { - /* my_thread_init() */ /* This may give extra safety */ - my_end(0); - } - break; - case DLL_THREAD_DETACH: - /* Main thread will free by my_end() */ - threads--; - if (main_thread != GetCurrentThreadId()) - my_thread_end(); - break; - default: - break; - } /* switch */ - - return TRUE; - - UNREFERENCED_PARAMETER(lpReserved); -} /* LibMain */ - - -static BOOL do_libmain; -int __stdcall DllMain(HANDLE hInst,DWORD ul_reason_being_called,LPVOID lpReserved) -{ - /* - Unless environment variable LIBMYSQL_DLLINIT is set, do nothing. - The environment variable is checked once, during the first call to DllMain() - (in DLL_PROCESS_ATTACH hook). - */ - if (ul_reason_being_called == DLL_PROCESS_ATTACH) - do_libmain = (getenv("LIBMYSQL_DLLINIT") != NULL); - if (do_libmain) - return LibMain(hInst,ul_reason_being_called,lpReserved); - return TRUE; -} - -#elif defined(WINDOWS) - -/**************************************************************************** -** This routine is called by LIBSTART.ASM at module load time. All it -** does in this sample is remember the DLL module handle. The module -** handle is needed if you want to do things like load stuff from the -** resource file (for instance string resources). -****************************************************************************/ - -int _export FAR PASCAL libmain(HANDLE hModule,short cbHeapSize, - UCHAR FAR *lszCmdLine) -{ - s_hModule = hModule; - libmysql_init(); - return TRUE; -} - -#endif