Author: wrowe Date: Sat Jan 1 12:56:44 2005 New Revision: 123856 URL: http://svn.apache.org/viewcvs?view=rev&rev=123856 Log:
Refactor asp_module_lock; * Track the version, use an appropriate asp_module_lock() function to use non-Unicode API on Win98/ME, Unicode otherwise. * Unlock the self-lock of the mod_aspdotnet.so module at the true termination of Apache. * Clean up some code which is no longer needed, we can't co-locate Apache.Web.dll outside of the GAC. Modified: httpd/mod_aspdotnet/trunk/mod/mod_aspdotnet.cpp Modified: httpd/mod_aspdotnet/trunk/mod/mod_aspdotnet.cpp Url: http://svn.apache.org/viewcvs/httpd/mod_aspdotnet/trunk/mod/mod_aspdotnet.cpp?view=diff&rev=123856&p1=httpd/mod_aspdotnet/trunk/mod/mod_aspdotnet.cpp&r1=123855&p2=httpd/mod_aspdotnet/trunk/mod/mod_aspdotnet.cpp&r2=123856 ============================================================================== --- httpd/mod_aspdotnet/trunk/mod/mod_aspdotnet.cpp (original) +++ httpd/mod_aspdotnet/trunk/mod/mod_aspdotnet.cpp Sat Jan 1 12:56:44 2005 @@ -79,7 +79,8 @@ apr_hash_t *hosts; // Hash of asp_net_host_conf_t records ICorRuntimeHost *pCorRuntime; IApacheWebHostFactory *pHostFactory; - HANDLE lock_module; + HMODULE lock_module; + OSVERSIONINFO osver; } *global_conf; // Initialized for each restart @@ -193,31 +194,60 @@ global_conf->pCorRuntime->Stop(); global_conf->pCorRuntime->Release(); } + + if (global_conf->lock_module) + FreeLibrary(global_conf->lock_module); + return APR_SUCCESS; } -static HRESULT init_asp_engine(void) +static void asp_module_lock98(void) { - HRESULT hr; + // Get the path to this mod_aspdotnet module so that we can + // lock ourselves in-place for the lifetime of the server + char AspNetPath[APR_PATH_MAX]; + HMODULE hModule = GetModuleHandleA("mod_aspdotnet.so"); + if (!GetModuleFileNameA(hModule, AspNetPath, APR_PATH_MAX)) { + HRESULT hr = GetLastError(); + apr_status_t rv = APR_FROM_OS_ERROR(hr); + ap_log_error(APLOG_MARK, APLOG_ERR, rv, NULL, + "mod_aspdotnet: Failed to discover the full file path to " + "mod_aspdotnet.so. (Was it renamed?)"); + _com_raise_error(hr); + } + // Lock in our module by incrementing its refcount. + global_conf->lock_module = LoadLibraryA(AspNetPath); +} + +static void asp_module_lock(void) +{ // Get the path to this mod_aspdotnet module so that we can // lock ourselves in-place for the lifetime of the server wchar_t wAspNetPath[APR_PATH_MAX]; HMODULE hModule = GetModuleHandleW(L"mod_aspdotnet.so"); - if (!GetModuleFileNameW(hModule, wAspNetPath, APR_PATH_MAX) - || (wcslen(wAspNetPath) >= APR_PATH_MAX - 1)) { - hr = GetLastError(); + if (!GetModuleFileNameW(hModule, wAspNetPath, APR_PATH_MAX)) { + HRESULT hr = GetLastError(); apr_status_t rv = APR_FROM_OS_ERROR(hr); - if (!rv) { - hr = E_FAIL; - rv = APR_ENAMETOOLONG; - } ap_log_error(APLOG_MARK, APLOG_ERR, rv, NULL, "mod_aspdotnet: Failed to discover the full file path to " "mod_aspdotnet.so. (Was it renamed?)"); _com_raise_error(hr); } + + // Lock in our module by incrementing its refcount. global_conf->lock_module = LoadLibraryW(wAspNetPath); +} + +static HRESULT init_asp_engine(void) +{ + global_conf->osver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); + GetVersionEx(&(global_conf->osver)); + + if (global_conf->osver.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) + asp_module_lock98(); + else + asp_module_lock(); // Now we are prepared to register our cleanup in the global // process pool, because we trust the module cannot be unloaded @@ -225,43 +255,23 @@ apr_pool_cleanup_register(global_conf->pool, NULL, asp_net_stop, apr_pool_cleanup_null); - // Now get the path to the apache.exe binary, as Apache.Web - // reside in the same path as the server's dll libraries. - if (!GetModuleFileNameW(NULL, wAspNetPath, APR_PATH_MAX) - || (wcslen(wAspNetPath) >= APR_PATH_MAX - 17)) { - hr = GetLastError(); - apr_status_t rv = APR_FROM_OS_ERROR(hr); - if (!rv) { - hr = E_FAIL; - rv = APR_ENAMETOOLONG; - } - ap_log_error(APLOG_MARK, APLOG_ERR, rv, NULL, - "mod_aspdotnet: Unable to determine apache.exe path!"); - _com_raise_error(hr); - } - - wchar_t *repl = wcsrchr(wAspNetPath, L'\\'); - if (!repl) { - ap_log_error(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, NULL, - "mod_aspdotnet: Unable to determine apache.exe path!"); - _com_raise_error(E_FAIL); - } - ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, NULL, - "mod_aspdotnet: Module initialization commencing..."); + "mod_aspdotnet: Module initialization commencing..."); + wchar_t wCORVersion[APR_PATH_MAX]; DWORD len; - hr = GetCORVersion(wAspNetPath, sizeof(wAspNetPath) + HRESULT hr; + hr = GetCORVersion(wCORVersion, sizeof(wCORVersion) / sizeof(WCHAR) - 1, &len); if (FAILED(hr)) { - wAspNetPath[len] = L'\0'; + wCORVersion[len] = L'\0'; ap_log_error(APLOG_MARK, APLOG_ERR, APR_FROM_OS_ERROR(hr), NULL, "mod_aspdotnet: GetCORVersion failed to return " "the .NET CLR engine version."); _com_raise_error(hr); } - hr = CorBindToRuntimeEx(wAspNetPath, + hr = CorBindToRuntimeEx(wCORVersion, L"svr", // Or "wks" STARTUP_LOADER_OPTIMIZATION_MULTI_DOMAIN_HOST | STARTUP_CONCURRENT_GC,