Switch to tracing macros in application info (#965)

This commit is contained in:
Pavel Krymets 2018-06-25 08:38:46 -07:00 committed by GitHub
parent 32121abde3
commit aeebcdefc1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 86 deletions

View File

@ -66,32 +66,10 @@ APPLICATION_INFO::Initialize(
// todo: make sure Initialize should be called only once // todo: make sure Initialize should be called only once
m_pServer = pServer; m_pServer = pServer;
m_pConfiguration = new ASPNETCORE_SHIM_CONFIG(); FINISHED_IF_NULL_ALLOC(m_pConfiguration = new ASPNETCORE_SHIM_CONFIG());
FINISHED_IF_FAILED(m_pConfiguration->Populate(m_pServer, pApplication));
if (m_pConfiguration == NULL) FINISHED_IF_FAILED(m_struInfoKey.Copy(pApplication->GetApplicationId()));
{ FINISHED_IF_NULL_ALLOC(m_pFileWatcherEntry = new FILE_WATCHER_ENTRY(pFileWatcher));
hr = E_OUTOFMEMORY;
goto Finished;
}
hr = m_pConfiguration->Populate(m_pServer, pApplication);
if (FAILED(hr))
{
goto Finished;
}
hr = m_struInfoKey.Copy(pApplication->GetApplicationId());
if (FAILED(hr))
{
goto Finished;
}
m_pFileWatcherEntry = new FILE_WATCHER_ENTRY(pFileWatcher);
if (m_pFileWatcherEntry == NULL)
{
hr = E_OUTOFMEMORY;
goto Finished;
}
UpdateAppOfflineFileHandle(); UpdateAppOfflineFileHandle();
@ -102,12 +80,11 @@ Finished:
HRESULT HRESULT
APPLICATION_INFO::StartMonitoringAppOffline() APPLICATION_INFO::StartMonitoringAppOffline()
{ {
HRESULT hr = S_OK;
if (m_pFileWatcherEntry != NULL) if (m_pFileWatcherEntry != NULL)
{ {
hr = m_pFileWatcherEntry->Create(m_pConfiguration->QueryApplicationPhysicalPath()->QueryStr(), L"app_offline.htm", this, NULL); RETURN_IF_FAILED(m_pFileWatcherEntry->Create(m_pConfiguration->QueryApplicationPhysicalPath()->QueryStr(), L"app_offline.htm", this, NULL));
} }
return hr; return S_OK;
} }
// //
@ -249,8 +226,7 @@ APPLICATION_INFO::FindRequestHandlerAssembly(STRU& location)
if (g_fAspnetcoreRHLoadedError) if (g_fAspnetcoreRHLoadedError)
{ {
hr = E_APPLICATION_ACTIVATION_EXEC_FAILURE; FINISHED_IF_FAILED(E_APPLICATION_ACTIVATION_EXEC_FAILURE);
goto Finished;
} }
else if (!g_fAspnetcoreRHAssemblyLoaded) else if (!g_fAspnetcoreRHAssemblyLoaded)
{ {
@ -258,12 +234,11 @@ APPLICATION_INFO::FindRequestHandlerAssembly(STRU& location)
if (g_fAspnetcoreRHLoadedError) if (g_fAspnetcoreRHLoadedError)
{ {
hr = E_APPLICATION_ACTIVATION_EXEC_FAILURE; FINISHED_IF_FAILED(E_APPLICATION_ACTIVATION_EXEC_FAILURE);
goto Finished;
} }
if (g_fAspnetcoreRHAssemblyLoaded) if (g_fAspnetcoreRHAssemblyLoaded)
{ {
goto Finished; FINISHED(S_OK);
} }
if (m_pConfiguration->QueryHostingModel() == APP_HOSTING_MODEL::HOSTING_IN_PROCESS) if (m_pConfiguration->QueryHostingModel() == APP_HOSTING_MODEL::HOSTING_IN_PROCESS)
@ -302,7 +277,7 @@ APPLICATION_INFO::FindRequestHandlerAssembly(STRU& location)
ASPNETCORE_EVENT_INPROCESS_RH_MISSING_MSG, ASPNETCORE_EVENT_INPROCESS_RH_MISSING_MSG,
struFileName.IsEmpty() ? s_pwzAspnetcoreInProcessRequestHandlerName : struFileName.QueryStr()); struFileName.IsEmpty() ? s_pwzAspnetcoreInProcessRequestHandlerName : struFileName.QueryStr());
goto Finished; FINISHED(hr);
} }
} }
else else
@ -315,7 +290,7 @@ APPLICATION_INFO::FindRequestHandlerAssembly(STRU& location)
ASPNETCORE_EVENT_OUT_OF_PROCESS_RH_MISSING_MSG, ASPNETCORE_EVENT_OUT_OF_PROCESS_RH_MISSING_MSG,
struFileName.IsEmpty() ? s_pwzAspnetcoreOutOfProcessRequestHandlerName : struFileName.QueryStr()); struFileName.IsEmpty() ? s_pwzAspnetcoreOutOfProcessRequestHandlerName : struFileName.QueryStr());
goto Finished; FINISHED(hr);
} }
} }
@ -325,8 +300,7 @@ APPLICATION_INFO::FindRequestHandlerAssembly(STRU& location)
if (g_hAspnetCoreRH == NULL) if (g_hAspnetCoreRH == NULL)
{ {
hr = HRESULT_FROM_WIN32(GetLastError()); FINISHED(HRESULT_FROM_WIN32(GetLastError()));
goto Finished;
} }
} }
@ -334,8 +308,7 @@ APPLICATION_INFO::FindRequestHandlerAssembly(STRU& location)
GetProcAddress(g_hAspnetCoreRH, "CreateApplication"); GetProcAddress(g_hAspnetCoreRH, "CreateApplication");
if (g_pfnAspNetCoreCreateApplication == NULL) if (g_pfnAspNetCoreCreateApplication == NULL)
{ {
hr = HRESULT_FROM_WIN32(GetLastError()); FINISHED(HRESULT_FROM_WIN32(GetLastError()));
goto Finished;
} }
g_fAspnetcoreRHAssemblyLoaded = TRUE; g_fAspnetcoreRHAssemblyLoaded = TRUE;
@ -374,10 +347,7 @@ APPLICATION_INFO::FindNativeAssemblyFromGlobalLocation(
pstrHandlerDllName pstrHandlerDllName
); );
if (FAILED(hr = struFilename->Copy(retval.c_str()))) RETURN_IF_FAILED(struFilename->Copy(retval.c_str()));
{
return hr;
}
} }
catch (std::exception& e) catch (std::exception& e)
{ {
@ -427,14 +397,7 @@ APPLICATION_INFO::FindNativeAssemblyFromHostfxr(
DBG_ASSERT(struFileName != NULL); DBG_ASSERT(struFileName != NULL);
hmHostFxrDll = LoadLibraryW(hostfxrOptions->GetHostFxrLocation()); FINISHED_LAST_ERROR_IF_NULL(hmHostFxrDll = LoadLibraryW(hostfxrOptions->GetHostFxrLocation()));
if (hmHostFxrDll == NULL)
{
// Could not load hostfxr
hr = HRESULT_FROM_WIN32(GetLastError());
goto Finished;
}
hostfxr_get_native_search_directories_fn pFnHostFxrSearchDirectories = (hostfxr_get_native_search_directories_fn) hostfxr_get_native_search_directories_fn pFnHostFxrSearchDirectories = (hostfxr_get_native_search_directories_fn)
GetProcAddress(hmHostFxrDll, "hostfxr_get_native_search_directories"); GetProcAddress(hmHostFxrDll, "hostfxr_get_native_search_directories");
@ -443,14 +406,10 @@ APPLICATION_INFO::FindNativeAssemblyFromHostfxr(
{ {
// Host fxr version is incorrect (need a higher version). // Host fxr version is incorrect (need a higher version).
// TODO log error // TODO log error
hr = E_FAIL; FINISHED(E_FAIL);
goto Finished;
} }
if (FAILED(hr = struNativeSearchPaths.Resize(dwBufferSize))) FINISHED_IF_FAILED(hr = struNativeSearchPaths.Resize(dwBufferSize));
{
goto Finished;
}
while (TRUE) while (TRUE)
{ {
@ -470,23 +429,16 @@ APPLICATION_INFO::FindNativeAssemblyFromHostfxr(
{ {
dwBufferSize = dwRequiredBufferSize + 1; // for null terminator dwBufferSize = dwRequiredBufferSize + 1; // for null terminator
if (FAILED(hr = struNativeSearchPaths.Resize(dwBufferSize))) FINISHED_IF_FAILED(struNativeSearchPaths.Resize(dwBufferSize));
{
goto Finished;
}
} }
else else
{ {
hr = E_FAIL;
// Log "Error finding native search directories from aspnetcore application. // Log "Error finding native search directories from aspnetcore application.
goto Finished; FINISHED(E_FAIL);
} }
} }
if (FAILED(hr = struNativeSearchPaths.SyncWithBuffer())) FINISHED_IF_FAILED(hr = struNativeSearchPaths.SyncWithBuffer());
{
goto Finished;
}
fFound = FALSE; fFound = FALSE;
@ -494,30 +446,18 @@ APPLICATION_INFO::FindNativeAssemblyFromHostfxr(
// Split on semicolons, append aspnetcorerh.dll, and check if the file exists. // Split on semicolons, append aspnetcorerh.dll, and check if the file exists.
while ((intIndex = struNativeSearchPaths.IndexOf(L";", intPrevIndex)) != -1) while ((intIndex = struNativeSearchPaths.IndexOf(L";", intPrevIndex)) != -1)
{ {
if (FAILED(hr = struNativeDllLocation.Copy(&struNativeSearchPaths.QueryStr()[intPrevIndex], intIndex - intPrevIndex))) FINISHED_IF_FAILED(struNativeDllLocation.Copy(&struNativeSearchPaths.QueryStr()[intPrevIndex], intIndex - intPrevIndex));
{
goto Finished;
}
if (!struNativeDllLocation.EndsWith(L"\\")) if (!struNativeDllLocation.EndsWith(L"\\"))
{ {
if (FAILED(hr = struNativeDllLocation.Append(L"\\"))) FINISHED_IF_FAILED(struNativeDllLocation.Append(L"\\"));
{
goto Finished;
}
} }
if (FAILED(hr = struNativeDllLocation.Append(libraryName))) FINISHED_IF_FAILED(struNativeDllLocation.Append(libraryName));
{
goto Finished;
}
if (UTILITY::CheckIfFileExists(struNativeDllLocation.QueryStr())) if (UTILITY::CheckIfFileExists(struNativeDllLocation.QueryStr()))
{ {
if (FAILED(hr = struFilename->Copy(struNativeDllLocation))) FINISHED_IF_FAILED(struFilename->Copy(struNativeDllLocation));
{
goto Finished;
}
fFound = TRUE; fFound = TRUE;
break; break;
} }
@ -527,8 +467,7 @@ APPLICATION_INFO::FindNativeAssemblyFromHostfxr(
if (!fFound) if (!fFound)
{ {
hr = E_FAIL; FINISHED(E_FAIL);
goto Finished;
} }
Finished: Finished:

View File

@ -31,6 +31,7 @@
#define RETURN_LAST_ERROR_IF(condition) do { if (condition) { return LogLastError(LOCATION_INFO); }} while (0, 0) #define RETURN_LAST_ERROR_IF(condition) do { if (condition) { return LogLastError(LOCATION_INFO); }} while (0, 0)
#define RETURN_LAST_ERROR_IF_NULL(ptr) do { if ((ptr) == nullptr) { return LogLastError(LOCATION_INFO); }} while (0, 0) #define RETURN_LAST_ERROR_IF_NULL(ptr) do { if ((ptr) == nullptr) { return LogLastError(LOCATION_INFO); }} while (0, 0)
#define FINISHED(hrr) do { HRESULT __hrRet = hrr; LogHResultFailed(LOCATION_INFO, __hrRet); hr = __hrRet; goto Finished; } while (0, 0)
#define FINISHED_IF_FAILED(hrr) do { HRESULT __hrRet = hrr; if (FAILED(__hrRet)) { LogHResultFailed(LOCATION_INFO, __hrRet); hr = __hrRet; goto Finished; }} while (0, 0) #define FINISHED_IF_FAILED(hrr) do { HRESULT __hrRet = hrr; if (FAILED(__hrRet)) { LogHResultFailed(LOCATION_INFO, __hrRet); hr = __hrRet; goto Finished; }} while (0, 0)
#define FINISHED_IF_NULL_ALLOC(ptr) do { if ((ptr) == nullptr) { hr = LogHResultFailed(LOCATION_INFO, E_OUTOFMEMORY); goto Finished; }} while (0, 0) #define FINISHED_IF_NULL_ALLOC(ptr) do { if ((ptr) == nullptr) { hr = LogHResultFailed(LOCATION_INFO, E_OUTOFMEMORY); goto Finished; }} while (0, 0)
#define FINISHED_LAST_ERROR_IF(condition) do { if (condition) { hr = LogLastError(LOCATION_INFO); goto Finished; }} while (0, 0) #define FINISHED_LAST_ERROR_IF(condition) do { if (condition) { hr = LogLastError(LOCATION_INFO); goto Finished; }} while (0, 0)