Merge pull request #764 from aspnet/pakrym/cleanup-logs

Cleanup LogEvent calls
This commit is contained in:
Pavel Krymets 2018-04-09 15:28:27 -07:00 committed by GitHub
commit 6e54256fca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 240 additions and 342 deletions

View File

@ -15,7 +15,7 @@ APPLICATION_INFO::~APPLICATION_INFO()
{ {
// Mark the entry as invalid, // Mark the entry as invalid,
// StopMonitor will close the file handle and trigger a FCN // StopMonitor will close the file handle and trigger a FCN
// the entry will delete itself when processing this FCN // the entry will delete itself when processing this FCN
m_pFileWatcherEntry->MarkEntryInValid(); m_pFileWatcherEntry->MarkEntryInValid();
m_pFileWatcherEntry->StopMonitor(); m_pFileWatcherEntry->StopMonitor();
m_pFileWatcherEntry = NULL; m_pFileWatcherEntry = NULL;
@ -112,15 +112,10 @@ APPLICATION_INFO::UpdateAppOfflineFileHandle()
// if it was, log that app_offline has been dropped. // if it was, log that app_offline has been dropped.
if (m_fAppOfflineFound) if (m_fAppOfflineFound)
{ {
STACK_STRU(strEventMsg, 256); UTILITY::LogEvent(g_hEventLog,
if (SUCCEEDED(strEventMsg.SafeSnwprintf( EVENTLOG_INFORMATION_TYPE,
ASPNETCORE_EVENT_RECYCLE_APPOFFLINE_REMOVED_MSG))) ASPNETCORE_EVENT_RECYCLE_APPOFFLINE_REMOVED,
{ ASPNETCORE_EVENT_RECYCLE_APPOFFLINE_REMOVED_MSG);
UTILITY::LogEvent(g_hEventLog,
EVENTLOG_INFORMATION_TYPE,
ASPNETCORE_EVENT_RECYCLE_APPOFFLINE_REMOVED,
strEventMsg.QueryStr());
}
} }
m_fAppOfflineFound = FALSE; m_fAppOfflineFound = FALSE;
@ -157,16 +152,11 @@ APPLICATION_INFO::UpdateAppOfflineFileHandle()
// recycle the application // recycle the application
if (m_pApplication != NULL) if (m_pApplication != NULL)
{ {
STACK_STRU(strEventMsg, 256); UTILITY::LogEventF(g_hEventLog,
if (SUCCEEDED(strEventMsg.SafeSnwprintf( EVENTLOG_INFORMATION_TYPE,
ASPNETCORE_EVENT_RECYCLE_APPOFFLINE,
ASPNETCORE_EVENT_RECYCLE_APPOFFLINE_MSG, ASPNETCORE_EVENT_RECYCLE_APPOFFLINE_MSG,
m_pApplication->QueryConfig()->QueryApplicationPath()->QueryStr()))) m_pApplication->QueryConfig()->QueryApplicationPath()->QueryStr());
{
UTILITY::LogEvent(g_hEventLog,
EVENTLOG_INFORMATION_TYPE,
ASPNETCORE_EVENT_RECYCLE_APPOFFLINE,
strEventMsg.QueryStr());
}
RecycleApplication(); RecycleApplication();
} }
@ -268,32 +258,20 @@ APPLICATION_INFO::FindRequestHandlerAssembly()
{ {
if (FAILED(hr = FindNativeAssemblyFromHostfxr(&struFileName))) if (FAILED(hr = FindNativeAssemblyFromHostfxr(&struFileName)))
{ {
STACK_STRU(strEventMsg, 256); UTILITY::LogEvent(g_hEventLog,
if (SUCCEEDED(strEventMsg.SafeSnwprintf(
ASPNETCORE_EVENT_INPROCESS_RH_MISSING_MSG)))
{
UTILITY::LogEvent(g_hEventLog,
EVENTLOG_INFORMATION_TYPE, EVENTLOG_INFORMATION_TYPE,
ASPNETCORE_EVENT_INPROCESS_RH_MISSING, ASPNETCORE_EVENT_INPROCESS_RH_MISSING,
strEventMsg.QueryStr()); ASPNETCORE_EVENT_INPROCESS_RH_MISSING_MSG);
}
goto Finished;
} }
} }
else else
{ {
if (FAILED(hr = FindNativeAssemblyFromGlobalLocation(&struFileName))) if (FAILED(hr = FindNativeAssemblyFromGlobalLocation(&struFileName)))
{ {
STACK_STRU(strEventMsg, 256); UTILITY::LogEvent(g_hEventLog,
if (SUCCEEDED(strEventMsg.SafeSnwprintf( EVENTLOG_INFORMATION_TYPE,
ASPNETCORE_EVENT_OUT_OF_PROCESS_RH_MISSING_MSG))) ASPNETCORE_EVENT_OUT_OF_PROCESS_RH_MISSING,
{ ASPNETCORE_EVENT_OUT_OF_PROCESS_RH_MISSING_MSG);
UTILITY::LogEvent(g_hEventLog,
EVENTLOG_INFORMATION_TYPE,
ASPNETCORE_EVENT_OUT_OF_PROCESS_RH_MISSING,
strEventMsg.QueryStr());
}
goto Finished; goto Finished;
} }
@ -327,7 +305,7 @@ APPLICATION_INFO::FindRequestHandlerAssembly()
Finished: Finished:
// //
// Question: we remember the load failure so that we will not try again. // Question: we remember the load failure so that we will not try again.
// User needs to check whether the fuction pointer is NULL // User needs to check whether the fuction pointer is NULL
// //
m_pfnAspNetCoreCreateApplication = g_pfnAspNetCoreCreateApplication; m_pfnAspNetCoreCreateApplication = g_pfnAspNetCoreCreateApplication;
m_pfnAspNetCoreCreateRequestHandler = g_pfnAspNetCoreCreateRequestHandler; m_pfnAspNetCoreCreateRequestHandler = g_pfnAspNetCoreCreateRequestHandler;
@ -400,11 +378,11 @@ Finished:
return hr; return hr;
} }
// //
// Tries to find aspnetcorerh.dll from the application // Tries to find aspnetcorerh.dll from the application
// Calls into hostfxr.dll to find it. // Calls into hostfxr.dll to find it.
// Will leave hostfxr.dll loaded as it will be used again to call hostfxr_main. // Will leave hostfxr.dll loaded as it will be used again to call hostfxr_main.
// //
HRESULT HRESULT
APPLICATION_INFO::FindNativeAssemblyFromHostfxr( APPLICATION_INFO::FindNativeAssemblyFromHostfxr(
STRU* struFilename STRU* struFilename
@ -439,7 +417,7 @@ APPLICATION_INFO::FindNativeAssemblyFromHostfxr(
if (pFnHostFxrSearchDirectories == NULL) if (pFnHostFxrSearchDirectories == NULL)
{ {
// 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; hr = E_FAIL;
goto Finished; goto Finished;
} }

View File

@ -24,7 +24,6 @@ APPLICATION_MANAGER::GetOrCreateApplicationInfo(
BOOL fMixedHostingModelError = FALSE; BOOL fMixedHostingModelError = FALSE;
BOOL fDuplicatedInProcessApp = FALSE; BOOL fDuplicatedInProcessApp = FALSE;
PCWSTR pszApplicationId = NULL; PCWSTR pszApplicationId = NULL;
STACK_STRU ( strEventMsg, 256 );
DBG_ASSERT(pServer); DBG_ASSERT(pServer);
DBG_ASSERT(pConfig); DBG_ASSERT(pConfig);
@ -32,9 +31,9 @@ APPLICATION_MANAGER::GetOrCreateApplicationInfo(
*ppApplicationInfo = NULL; *ppApplicationInfo = NULL;
// The configuration path is unique for each application and is used for the // The configuration path is unique for each application and is used for the
// key in the applicationInfoHash. // key in the applicationInfoHash.
pszApplicationId = pConfig->QueryConfigPath()->QueryStr(); pszApplicationId = pConfig->QueryConfigPath()->QueryStr();
hr = key.Initialize(pszApplicationId); hr = key.Initialize(pszApplicationId);
if (FAILED(hr)) if (FAILED(hr))
{ {
@ -55,7 +54,7 @@ APPLICATION_MANAGER::GetOrCreateApplicationInfo(
if (*ppApplicationInfo == NULL) if (*ppApplicationInfo == NULL)
{ {
// Check which hosting model we want to support // Check which hosting model we want to support
switch (pConfig->QueryHostingModel()) switch (pConfig->QueryHostingModel())
{ {
case HOSTING_IN_PROCESS: case HOSTING_IN_PROCESS:
@ -160,41 +159,29 @@ Finished:
{ {
if (fDuplicatedInProcessApp) if (fDuplicatedInProcessApp)
{ {
if (SUCCEEDED(strEventMsg.SafeSnwprintf( UTILITY::LogEventF(g_hEventLog,
EVENTLOG_ERROR_TYPE,
ASPNETCORE_EVENT_DUPLICATED_INPROCESS_APP,
ASPNETCORE_EVENT_DUPLICATED_INPROCESS_APP_MSG, ASPNETCORE_EVENT_DUPLICATED_INPROCESS_APP_MSG,
pszApplicationId))) pszApplicationId);
{
UTILITY::LogEvent(g_hEventLog,
EVENTLOG_ERROR_TYPE,
ASPNETCORE_EVENT_DUPLICATED_INPROCESS_APP,
strEventMsg.QueryStr());
}
} }
else if (fMixedHostingModelError) else if (fMixedHostingModelError)
{ {
if (SUCCEEDED(strEventMsg.SafeSnwprintf( UTILITY::LogEventF(g_hEventLog,
EVENTLOG_ERROR_TYPE,
ASPNETCORE_EVENT_MIXED_HOSTING_MODEL_ERROR,
ASPNETCORE_EVENT_MIXED_HOSTING_MODEL_ERROR_MSG, ASPNETCORE_EVENT_MIXED_HOSTING_MODEL_ERROR_MSG,
pszApplicationId, pszApplicationId,
pConfig->QueryHostingModel()))) pConfig->QueryHostingModel());
{
UTILITY::LogEvent(g_hEventLog,
EVENTLOG_ERROR_TYPE,
ASPNETCORE_EVENT_MIXED_HOSTING_MODEL_ERROR,
strEventMsg.QueryStr());
}
} }
else else
{ {
if (SUCCEEDED(strEventMsg.SafeSnwprintf( UTILITY::LogEventF(g_hEventLog,
EVENTLOG_ERROR_TYPE,
ASPNETCORE_EVENT_ADD_APPLICATION_ERROR,
ASPNETCORE_EVENT_ADD_APPLICATION_ERROR_MSG, ASPNETCORE_EVENT_ADD_APPLICATION_ERROR_MSG,
pszApplicationId, pszApplicationId,
hr))) hr);
{
UTILITY::LogEvent(g_hEventLog,
EVENTLOG_ERROR_TYPE,
ASPNETCORE_EVENT_ADD_APPLICATION_ERROR,
strEventMsg.QueryStr());
}
} }
} }
@ -215,7 +202,7 @@ APPLICATION_MANAGER::FindConfigChangedApplication(
DBG_ASSERT(pvContext); DBG_ASSERT(pvContext);
// Config Change context contains the original config path that changed // Config Change context contains the original config path that changed
// and a multiStr containing // and a multiStr containing
CONFIG_CHANGE_CONTEXT* pContext = static_cast<CONFIG_CHANGE_CONTEXT*>(pvContext); CONFIG_CHANGE_CONTEXT* pContext = static_cast<CONFIG_CHANGE_CONTEXT*>(pvContext);
STRU* pstruConfigPath = pEntry->QueryConfig()->QueryConfigPath(); STRU* pstruConfigPath = pEntry->QueryConfig()->QueryConfigPath();
@ -250,7 +237,7 @@ APPLICATION_MANAGER::FindConfigChangedApplication(
// This will cause a shutdown event to occur through the global stop listening event. // This will cause a shutdown event to occur through the global stop listening event.
// OutOfProcess: Removes all applications in the application manager and calls Recycle, which will call Shutdown, // OutOfProcess: Removes all applications in the application manager and calls Recycle, which will call Shutdown,
// on each application. // on each application.
// //
HRESULT HRESULT
APPLICATION_MANAGER::RecycleApplicationFromManager( APPLICATION_MANAGER::RecycleApplicationFromManager(
_In_ LPCWSTR pszApplicationId _In_ LPCWSTR pszApplicationId
@ -307,7 +294,7 @@ APPLICATION_MANAGER::RecycleApplicationFromManager(
// Don't call application shutdown inside the lock // Don't call application shutdown inside the lock
m_pApplicationInfoHash->Apply(APPLICATION_INFO_HASH::ReferenceCopyToTable, static_cast<PVOID>(table)); m_pApplicationInfoHash->Apply(APPLICATION_INFO_HASH::ReferenceCopyToTable, static_cast<PVOID>(table));
DBG_ASSERT(dwPreviousCounter == table->Count()); DBG_ASSERT(dwPreviousCounter == table->Count());
// Removed the applications which are impacted by the configurtion change // Removed the applications which are impacted by the configurtion change
m_pApplicationInfoHash->DeleteIf(FindConfigChangedApplication, (PVOID)&context); m_pApplicationInfoHash->DeleteIf(FindConfigChangedApplication, (PVOID)&context);
@ -349,16 +336,11 @@ APPLICATION_MANAGER::RecycleApplicationFromManager(
APPLICATION_INFO* pRecord; APPLICATION_INFO* pRecord;
// Application got recycled. Log an event // Application got recycled. Log an event
STACK_STRU(strEventMsg, 256); UTILITY::LogEventF(g_hEventLog,
if (SUCCEEDED(strEventMsg.SafeSnwprintf( EVENTLOG_INFORMATION_TYPE,
ASPNETCORE_EVENT_RECYCLE_CONFIGURATION,
ASPNETCORE_EVENT_RECYCLE_CONFIGURATION_MSG, ASPNETCORE_EVENT_RECYCLE_CONFIGURATION_MSG,
path))) path);
{
UTILITY::LogEvent(g_hEventLog,
EVENTLOG_INFORMATION_TYPE,
ASPNETCORE_EVENT_RECYCLE_CONFIGURATION,
strEventMsg.QueryStr());
}
hr = key.Initialize(path); hr = key.Initialize(path);
if (FAILED(hr)) if (FAILED(hr))
@ -369,7 +351,7 @@ APPLICATION_MANAGER::RecycleApplicationFromManager(
table->FindKey(&key, &pRecord); table->FindKey(&key, &pRecord);
DBG_ASSERT(pRecord != NULL); DBG_ASSERT(pRecord != NULL);
// RecycleApplication is called on a separate thread. // RecycleApplication is called on a separate thread.
pRecord->RecycleApplication(); pRecord->RecycleApplication();
pRecord->DereferenceApplicationInfo(); pRecord->DereferenceApplicationInfo();
path = context.MultiSz.Next(path); path = context.MultiSz.Next(path);
@ -386,16 +368,11 @@ Finished:
if (FAILED(hr)) if (FAILED(hr))
{ {
// Failed to recycle an application. Log an event // Failed to recycle an application. Log an event
STACK_STRU(strEventMsg, 256); UTILITY::LogEventF(g_hEventLog,
if (SUCCEEDED(strEventMsg.SafeSnwprintf( EVENTLOG_ERROR_TYPE,
ASPNETCORE_EVENT_RECYCLE_FAILURE_CONFIGURATION_MSG, ASPNETCORE_EVENT_RECYCLE_APP_FAILURE,
pszApplicationId))) ASPNETCORE_EVENT_RECYCLE_FAILURE_CONFIGURATION_MSG,
{ pszApplicationId);
UTILITY::LogEvent(g_hEventLog,
EVENTLOG_ERROR_TYPE,
ASPNETCORE_EVENT_RECYCLE_APP_FAILURE,
strEventMsg.QueryStr());
}
// Need to recycle the process as we cannot recycle the application // Need to recycle the process as we cannot recycle the application
if (!g_fRecycleProcessCalled) if (!g_fRecycleProcessCalled)
{ {
@ -410,7 +387,7 @@ Finished:
// //
// Shutsdown all applications in the application hashtable // Shutsdown all applications in the application hashtable
// Only called by OnGlobalStopListening. // Only called by OnGlobalStopListening.
// //
VOID VOID
APPLICATION_MANAGER::ShutDown() APPLICATION_MANAGER::ShutDown()
{ {
@ -427,7 +404,7 @@ APPLICATION_MANAGER::ShutDown()
} }
DBG_ASSERT(m_pApplicationInfoHash); DBG_ASSERT(m_pApplicationInfoHash);
// During shutdown we lock until we delete the application // During shutdown we lock until we delete the application
AcquireSRWLockExclusive(&m_srwLock); AcquireSRWLockExclusive(&m_srwLock);
// Call shutdown on each application in the application manager // Call shutdown on each application in the application manager

View File

@ -49,7 +49,7 @@ BOOL WINAPI DllMain(HMODULE hModule,
break; break;
case DLL_PROCESS_DETACH: case DLL_PROCESS_DETACH:
// IIS can cause dll detach to occur before we receive global notifications // IIS can cause dll detach to occur before we receive global notifications
// For example, when we switch the bitness of the worker process, // For example, when we switch the bitness of the worker process,
// this is a bug in IIS. To try to avoid AVs, we will set a global flag // this is a bug in IIS. To try to avoid AVs, we will set a global flag
g_fInShutdown = TRUE; g_fInShutdown = TRUE;
StaticCleanup(); StaticCleanup();
@ -160,16 +160,10 @@ HRESULT
if (fDisableANCM) if (fDisableANCM)
{ {
// Logging UTILITY::LogEvent(g_hEventLog,
STACK_STRU(strEventMsg, 256); EVENTLOG_WARNING_TYPE,
if (SUCCEEDED(strEventMsg.SafeSnwprintf( ASPNETCORE_EVENT_MODULE_DISABLED,
ASPNETCORE_EVENT_MODULE_DISABLED_MSG))) ASPNETCORE_EVENT_MODULE_DISABLED_MSG);
{
UTILITY::LogEvent(g_hEventLog,
EVENTLOG_WARNING_TYPE,
ASPNETCORE_EVENT_MODULE_DISABLED,
strEventMsg.QueryStr());
}
// this will return 500 error to client // this will return 500 error to client
// as we did not register the module // as we did not register the module
goto Finished; goto Finished;
@ -204,7 +198,7 @@ HRESULT
hr = E_OUTOFMEMORY; hr = E_OUTOFMEMORY;
goto Finished; goto Finished;
} }
hr = pApplicationManager->Initialize(); hr = pApplicationManager->Initialize();
if(FAILED(hr)) if(FAILED(hr))
{ {

View File

@ -39,7 +39,6 @@ HOSTFXR_UTILITY::GetStandaloneHostfxrParameters(
STRU struArguments; STRU struArguments;
STRU struHostFxrPath; STRU struHostFxrPath;
STRU struRuntimeConfigLocation; STRU struRuntimeConfigLocation;
STRU strEventMsg;
DWORD dwPosition; DWORD dwPosition;
// Obtain the app name from the processPath section. // Obtain the app name from the processPath section.
@ -80,31 +79,23 @@ HOSTFXR_UTILITY::GetStandaloneHostfxrParameters(
{ {
hr = E_APPLICATION_ACTIVATION_EXEC_FAILURE; hr = E_APPLICATION_ACTIVATION_EXEC_FAILURE;
if (SUCCEEDED(strEventMsg.SafeSnwprintf( UTILITY::LogEventF(hEventLog,
ASPNETCORE_EVENT_INPROCESS_FULL_FRAMEWORK_APP_MSG, EVENTLOG_ERROR_TYPE,
pcwzApplicationPhysicalPath, ASPNETCORE_EVENT_INPROCESS_FULL_FRAMEWORK_APP,
hr))) ASPNETCORE_EVENT_INPROCESS_FULL_FRAMEWORK_APP_MSG,
{ pcwzApplicationPhysicalPath,
UTILITY::LogEvent( hEventLog, hr);
EVENTLOG_ERROR_TYPE,
ASPNETCORE_EVENT_INPROCESS_FULL_FRAMEWORK_APP,
strEventMsg.QueryStr() );
}
} }
else else
{ {
// If a runtime config file does exist, report a file not found on the app.exe // If a runtime config file does exist, report a file not found on the app.exe
hr = HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND); hr = HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
if (SUCCEEDED(strEventMsg.SafeSnwprintf( UTILITY::LogEventF(hEventLog,
ASPNETCORE_EVENT_APPLICATION_EXE_NOT_FOUND_MSG, EVENTLOG_ERROR_TYPE,
ASPNETCORE_EVENT_APPLICATION_EXE_NOT_FOUND,
ASPNETCORE_EVENT_APPLICATION_EXE_NOT_FOUND_MSG,
pcwzApplicationPhysicalPath, pcwzApplicationPhysicalPath,
hr))) hr);
{
UTILITY::LogEvent(hEventLog,
EVENTLOG_ERROR_TYPE,
ASPNETCORE_EVENT_APPLICATION_EXE_NOT_FOUND,
strEventMsg.QueryStr());
}
} }
goto Finished; goto Finished;
@ -190,12 +181,12 @@ HOSTFXR_UTILITY::GetHostFxrParameters(
goto Finished; goto Finished;
} }
// Check if the absolute path is to dotnet or not. // Check if the absolute path is to dotnet or not.
if (struAbsolutePathToDotnet.EndsWith(L"dotnet.exe") || struAbsolutePathToDotnet.EndsWith(L"dotnet")) if (struAbsolutePathToDotnet.EndsWith(L"dotnet.exe") || struAbsolutePathToDotnet.EndsWith(L"dotnet"))
{ {
// //
// The processPath ends with dotnet.exe or dotnet // The processPath ends with dotnet.exe or dotnet
// like: C:\Program Files\dotnet\dotnet.exe, C:\Program Files\dotnet\dotnet, dotnet.exe, or dotnet. // like: C:\Program Files\dotnet\dotnet.exe, C:\Program Files\dotnet\dotnet, dotnet.exe, or dotnet.
// Get the absolute path to dotnet. If the path is already an absolute path, it will return that path // Get the absolute path to dotnet. If the path is already an absolute path, it will return that path
// //
if (FAILED(hr = HOSTFXR_UTILITY::GetAbsolutePathToDotnet(&struAbsolutePathToDotnet))) // Make sure to append the dotnet.exe path correctly here (pass in regular path)? if (FAILED(hr = HOSTFXR_UTILITY::GetAbsolutePathToDotnet(&struAbsolutePathToDotnet))) // Make sure to append the dotnet.exe path correctly here (pass in regular path)?
@ -249,16 +240,12 @@ HOSTFXR_UTILITY::GetHostFxrParameters(
// then it is an invalid argument. // then it is an invalid argument.
// //
hr = HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);; hr = HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);;
if (SUCCEEDED(struEventMsg.SafeSnwprintf( UTILITY::LogEventF(hEventLog,
EVENTLOG_ERROR_TYPE,
ASPNETCORE_EVENT_GENERAL_ERROR_MSG,
ASPNETCORE_EVENT_INVALID_PROCESS_PATH_MSG, ASPNETCORE_EVENT_INVALID_PROCESS_PATH_MSG,
struExpandedProcessPath.QueryStr(), struExpandedProcessPath.QueryStr(),
hr))) hr);
{
UTILITY::LogEvent(hEventLog,
EVENTLOG_ERROR_TYPE,
ASPNETCORE_EVENT_GENERAL_ERROR_MSG,
struEventMsg.QueryStr());
}
} }
} }
@ -273,8 +260,8 @@ Finished:
// Arg structure: // Arg structure:
// argv[0] = Path to exe activating hostfxr. // argv[0] = Path to exe activating hostfxr.
// argv[1] = L"exec" // argv[1] = L"exec"
// argv[2] = absolute path to dll. // argv[2] = absolute path to dll.
// //
HRESULT HRESULT
HOSTFXR_UTILITY::ParseHostfxrArguments( HOSTFXR_UTILITY::ParseHostfxrArguments(
PCWSTR pwzArgumentsFromConfig, PCWSTR pwzArgumentsFromConfig,
@ -473,16 +460,13 @@ HOSTFXR_UTILITY::GetAbsolutePathToHostFxr(
if (!UTILITY::DirectoryExists(&struHostFxrPath)) if (!UTILITY::DirectoryExists(&struHostFxrPath))
{ {
hr = ERROR_BAD_ENVIRONMENT; hr = ERROR_BAD_ENVIRONMENT;
if (SUCCEEDED(struEventMsg.SafeSnwprintf( UTILITY::LogEventF(hEventLog,
EVENTLOG_ERROR_TYPE,
ASPNETCORE_EVENT_HOSTFXR_DIRECTORY_NOT_FOUND,
struEventMsg.QueryStr(),
ASPNETCORE_EVENT_HOSTFXR_DIRECTORY_NOT_FOUND_MSG, ASPNETCORE_EVENT_HOSTFXR_DIRECTORY_NOT_FOUND_MSG,
struHostFxrPath.QueryStr(), struHostFxrPath.QueryStr(),
hr))) hr);
{
UTILITY::LogEvent(hEventLog,
EVENTLOG_ERROR_TYPE,
ASPNETCORE_EVENT_HOSTFXR_DIRECTORY_NOT_FOUND,
struEventMsg.QueryStr());
}
goto Finished; goto Finished;
} }
@ -505,16 +489,12 @@ HOSTFXR_UTILITY::GetAbsolutePathToHostFxr(
if (vVersionFolders.size() == 0) if (vVersionFolders.size() == 0)
{ {
hr = HRESULT_FROM_WIN32(ERROR_BAD_ENVIRONMENT); hr = HRESULT_FROM_WIN32(ERROR_BAD_ENVIRONMENT);
if (SUCCEEDED(struEventMsg.SafeSnwprintf( UTILITY::LogEventF(hEventLog,
EVENTLOG_ERROR_TYPE,
ASPNETCORE_EVENT_HOSTFXR_DIRECTORY_NOT_FOUND,
ASPNETCORE_EVENT_HOSTFXR_DIRECTORY_NOT_FOUND_MSG, ASPNETCORE_EVENT_HOSTFXR_DIRECTORY_NOT_FOUND_MSG,
struHostFxrPath.QueryStr(), struHostFxrPath.QueryStr(),
hr))) hr);
{
UTILITY::LogEvent(hEventLog,
EVENTLOG_ERROR_TYPE,
ASPNETCORE_EVENT_HOSTFXR_DIRECTORY_NOT_FOUND,
struEventMsg.QueryStr());
}
goto Finished; goto Finished;
} }
@ -535,16 +515,12 @@ HOSTFXR_UTILITY::GetAbsolutePathToHostFxr(
{ {
// ASPNETCORE_EVENT_HOSTFXR_DLL_NOT_FOUND_MSG // ASPNETCORE_EVENT_HOSTFXR_DLL_NOT_FOUND_MSG
hr = HRESULT_FROM_WIN32(ERROR_FILE_INVALID); hr = HRESULT_FROM_WIN32(ERROR_FILE_INVALID);
if (SUCCEEDED(struEventMsg.SafeSnwprintf( UTILITY::LogEventF(hEventLog,
EVENTLOG_ERROR_TYPE,
ASPNETCORE_EVENT_HOSTFXR_DLL_NOT_FOUND,
ASPNETCORE_EVENT_HOSTFXR_DLL_NOT_FOUND_MSG, ASPNETCORE_EVENT_HOSTFXR_DLL_NOT_FOUND_MSG,
struHostFxrPath.QueryStr(), struHostFxrPath.QueryStr(),
hr))) hr);
{
UTILITY::LogEvent(hEventLog,
EVENTLOG_ERROR_TYPE,
ASPNETCORE_EVENT_HOSTFXR_DLL_NOT_FOUND,
struEventMsg.QueryStr());
}
goto Finished; goto Finished;
} }
@ -657,7 +633,7 @@ HOSTFXR_UTILITY::InvokeWhereToFindDotnet(
// where.exe will return 0 on success, 1 if the file is not found // where.exe will return 0 on success, 1 if the file is not found
// and 2 if there was an error. Check if the exit code is 1 and set // and 2 if there was an error. Check if the exit code is 1 and set
// a new hr result saying it couldn't find dotnet.exe // a new hr result saying it couldn't find dotnet.exe
// //
if (!GetExitCodeProcess(processInformation.hProcess, &dwExitCode)) if (!GetExitCodeProcess(processInformation.hProcess, &dwExitCode))
{ {
goto Finished; goto Finished;
@ -666,14 +642,14 @@ HOSTFXR_UTILITY::InvokeWhereToFindDotnet(
// //
// In this block, if anything fails, we will goto our fallback of // In this block, if anything fails, we will goto our fallback of
// looking in C:/Program Files/ // looking in C:/Program Files/
// //
if (dwExitCode != 0) if (dwExitCode != 0)
{ {
goto Finished; goto Finished;
} }
// Where succeeded. // Where succeeded.
// Reset file pointer to the beginning of the file. // Reset file pointer to the beginning of the file.
dwFilePointer = SetFilePointer(hStdOutReadPipe, 0, NULL, FILE_BEGIN); dwFilePointer = SetFilePointer(hStdOutReadPipe, 0, NULL, FILE_BEGIN);
if (dwFilePointer == INVALID_SET_FILE_POINTER) if (dwFilePointer == INVALID_SET_FILE_POINTER)
{ {
@ -703,7 +679,7 @@ HOSTFXR_UTILITY::InvokeWhereToFindDotnet(
} }
// Check the bitness of the currently running process // Check the bitness of the currently running process
// matches the dotnet.exe found. // matches the dotnet.exe found.
if (!IsWow64Process(GetCurrentProcess(), &fIsWow64Process)) if (!IsWow64Process(GetCurrentProcess(), &fIsWow64Process))
{ {
// Calling IsWow64Process failed // Calling IsWow64Process failed
@ -716,7 +692,7 @@ HOSTFXR_UTILITY::InvokeWhereToFindDotnet(
} }
else else
{ {
// Check the SystemInfo to see if we are currently 32 or 64 bit. // Check the SystemInfo to see if we are currently 32 or 64 bit.
SYSTEM_INFO systemInfo; SYSTEM_INFO systemInfo;
GetNativeSystemInfo(&systemInfo); GetNativeSystemInfo(&systemInfo);
fIsCurrentProcess64Bit = systemInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64; fIsCurrentProcess64Bit = systemInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64;
@ -748,7 +724,7 @@ HOSTFXR_UTILITY::InvokeWhereToFindDotnet(
break; break;
} }
} }
Finished: Finished:
if (hStdOutReadPipe != INVALID_HANDLE_VALUE) if (hStdOutReadPipe != INVALID_HANDLE_VALUE)

View File

@ -28,7 +28,7 @@ Arguments:
pstrDestination - destination pstrDestination - destination
pDestinationPort - port pDestinationPort - port
pstrUrl - URL pstrUrl - URL
Return Value: Return Value:
HRESULT HRESULT
@ -260,7 +260,7 @@ UTILITY::EscapeAbsPath(
} }
strEscapedUrl->Append(pszAbsPath); strEscapedUrl->Append(pszAbsPath);
strEscapedUrl->Append(pRequest->GetRawHttpRequest()->CookedUrl.pQueryString, strEscapedUrl->Append(pRequest->GetRawHttpRequest()->CookedUrl.pQueryString,
pRequest->GetRawHttpRequest()->CookedUrl.QueryStringLength / sizeof(WCHAR)); pRequest->GetRawHttpRequest()->CookedUrl.QueryStringLength / sizeof(WCHAR));
Finished: Finished:
@ -343,8 +343,8 @@ UTILITY::IsValidHeaderName(
HRESULT HRESULT
UTILITY::IsPathUnc( UTILITY::IsPathUnc(
__in LPCWSTR pszPath, __in LPCWSTR pszPath,
__out BOOL * pfIsUnc __out BOOL * pfIsUnc
) )
{ {
HRESULT hr = S_OK; HRESULT hr = S_OK;
@ -484,7 +484,7 @@ UTILITY::EnsureDirectoryPathExist(
} }
else if (struPath.QueryStr()[dwPosition-1] == L':') else if (struPath.QueryStr()[dwPosition-1] == L':')
{ {
// skip volume case // skip volume case
continue; continue;
} }
else else
@ -627,3 +627,30 @@ UTILITY::LogEvent(
fwprintf(stderr, L"ERROR: %s\n", pstrMsg); fwprintf(stderr, L"ERROR: %s\n", pstrMsg);
} }
} }
VOID
UTILITY::LogEventF(
_In_ HANDLE hEventLog,
_In_ WORD dwEventInfoType,
_In_ DWORD dwEventId,
_In_ LPCWSTR pstrMsg,
...
)
{
va_list argsList;
va_start(argsList, pstrMsg);
STACK_STRU ( strEventMsg, 256 );
if (SUCCEEDED(strEventMsg.SafeSnwprintf(
pstrMsg,
argsList)))
{
UTILITY::LogEvent(hEventLog,
dwEventInfoType,
dwEventId,
strEventMsg.QueryStr());
}
va_end( argsList );
}

View File

@ -67,8 +67,8 @@ public:
static static
HRESULT HRESULT
IsPathUnc( IsPathUnc(
__in LPCWSTR pszPath, __in LPCWSTR pszPath,
__out BOOL * pfIsUnc __out BOOL * pfIsUnc
); );
static static
@ -120,6 +120,16 @@ public:
_In_ LPCWSTR pstrMsg _In_ LPCWSTR pstrMsg
); );
static
VOID
LogEventF(
_In_ HANDLE hEventLog,
_In_ WORD dwEventInfoType,
_In_ DWORD dwEventId,
__in PCWSTR pstrMsg,
...
);
private: private:
UTILITY() {} UTILITY() {}

View File

@ -103,17 +103,11 @@ Finished:
if (FAILED(hr)) if (FAILED(hr))
{ {
STACK_STRU(strEventMsg, 256); UTILITY::LogEventF(g_hEventLog,
EVENTLOG_WARNING_TYPE,
if (SUCCEEDED(strEventMsg.SafeSnwprintf( ASPNETCORE_EVENT_GRACEFUL_SHUTDOWN_FAILURE,
ASPNETCORE_EVENT_APP_SHUTDOWN_FAILURE_MSG, ASPNETCORE_EVENT_APP_SHUTDOWN_FAILURE_MSG,
m_pConfig->QueryConfigPath()->QueryStr()))) m_pConfig->QueryConfigPath()->QueryStr());
{
UTILITY::LogEvent(g_hEventLog,
EVENTLOG_WARNING_TYPE,
ASPNETCORE_EVENT_GRACEFUL_SHUTDOWN_FAILURE,
strEventMsg.QueryStr());
}
// //
// Managed layer may block the shutdown and lead to shutdown timeout // Managed layer may block the shutdown and lead to shutdown timeout
@ -177,7 +171,7 @@ IN_PROCESS_APPLICATION::ShutDownInternal()
ReleaseSRWLockExclusive(&m_srwLock); ReleaseSRWLockExclusive(&m_srwLock);
fLocked = FALSE; fLocked = FALSE;
// Release the lock before we wait on the thread to exit. // Release the lock before we wait on the thread to exit.
if (m_hThread != NULL && if (m_hThread != NULL &&
GetExitCodeThread(m_hThread, &dwThreadStatus) != 0 && GetExitCodeThread(m_hThread, &dwThreadStatus) != 0 &&
dwThreadStatus == STILL_ACTIVE) dwThreadStatus == STILL_ACTIVE)
@ -219,7 +213,7 @@ IN_PROCESS_APPLICATION::ShutDownInternal()
// delete empty log file // delete empty log file
handle = FindFirstFile(m_struLogFilePath.QueryStr(), &fileData); handle = FindFirstFile(m_struLogFilePath.QueryStr(), &fileData);
if (handle != INVALID_HANDLE_VALUE && if (handle != INVALID_HANDLE_VALUE &&
fileData.nFileSizeHigh == 0 && fileData.nFileSizeHigh == 0 &&
fileData.nFileSizeLow == 0) // skip check of nFileSizeHigh fileData.nFileSizeLow == 0) // skip check of nFileSizeHigh
{ {
FindClose(handle); FindClose(handle);
@ -244,7 +238,7 @@ IN_PROCESS_APPLICATION::Recycle(
{ {
BOOL fLockAcquired = FALSE; BOOL fLockAcquired = FALSE;
// We need to guarantee that recycle is only called once, as calling pHttpServer->RecycleProcess // We need to guarantee that recycle is only called once, as calling pHttpServer->RecycleProcess
// multiple times can lead to AVs. // multiple times can lead to AVs.
if (m_fRecycleCalled) if (m_fRecycleCalled)
{ {
goto Finished; goto Finished;
@ -565,17 +559,12 @@ Finished:
} }
if (FAILED(hr) && m_pConfig->QueryStdoutLogEnabled()) if (FAILED(hr) && m_pConfig->QueryStdoutLogEnabled())
{ {
STRU strEventMsg; UTILITY::LogEventF(g_hEventLog,
if (SUCCEEDED(strEventMsg.SafeSnwprintf( EVENTLOG_WARNING_TYPE,
ASPNETCORE_EVENT_CONFIG_ERROR,
ASPNETCORE_EVENT_INVALID_STDOUT_LOG_FILE_MSG, ASPNETCORE_EVENT_INVALID_STDOUT_LOG_FILE_MSG,
m_struLogFilePath.QueryStr(), m_struLogFilePath.QueryStr(),
hr))) hr);
{
UTILITY::LogEvent(g_hEventLog,
EVENTLOG_WARNING_TYPE,
ASPNETCORE_EVENT_CONFIG_ERROR,
strEventMsg.QueryStr());
}
} }
} }
@ -739,7 +728,7 @@ IN_PROCESS_APPLICATION::LoadManagedApplication
// Wait on either the thread to complete or the event to be set // Wait on either the thread to complete or the event to be set
dwResult = WaitForMultipleObjects(2, pHandles, FALSE, dwTimeout); dwResult = WaitForMultipleObjects(2, pHandles, FALSE, dwTimeout);
// It all timed out // It all timed out
if (dwResult == WAIT_TIMEOUT) if (dwResult == WAIT_TIMEOUT)
{ {
@ -767,20 +756,15 @@ Finished:
if (FAILED(hr)) if (FAILED(hr))
{ {
STACK_STRU(strEventMsg, 256);
m_status = APPLICATION_STATUS::FAIL; m_status = APPLICATION_STATUS::FAIL;
if (SUCCEEDED(strEventMsg.SafeSnwprintf( UTILITY::LogEventF(g_hEventLog,
EVENTLOG_ERROR_TYPE,
ASPNETCORE_EVENT_LOAD_CLR_FALIURE,
ASPNETCORE_EVENT_LOAD_CLR_FALIURE_MSG, ASPNETCORE_EVENT_LOAD_CLR_FALIURE_MSG,
m_pConfig->QueryApplicationPath()->QueryStr(), m_pConfig->QueryApplicationPath()->QueryStr(),
m_pConfig->QueryApplicationPhysicalPath()->QueryStr(), m_pConfig->QueryApplicationPhysicalPath()->QueryStr(),
hr))) hr);
{
UTILITY::LogEvent(g_hEventLog,
EVENTLOG_ERROR_TYPE,
ASPNETCORE_EVENT_LOAD_CLR_FALIURE,
strEventMsg.QueryStr());
}
} }
if (fLocked) if (fLocked)
@ -926,13 +910,12 @@ IN_PROCESS_APPLICATION::LogErrorsOnMainExit(
DWORD dwNumBytesRead; DWORD dwNumBytesRead;
STRU struStdErrLog; STRU struStdErrLog;
LARGE_INTEGER li = { 0 }; LARGE_INTEGER li = { 0 };
STRU strEventMsg;
BOOL fLogged = FALSE; BOOL fLogged = FALSE;
DWORD dwFilePointer = 0; DWORD dwFilePointer = 0;
if (m_pConfig->QueryStdoutLogEnabled()) if (m_pConfig->QueryStdoutLogEnabled())
{ {
// Put stdout/stderr logs into // Put stdout/stderr logs into
if (m_hLogFileHandle != INVALID_HANDLE_VALUE) if (m_hLogFileHandle != INVALID_HANDLE_VALUE)
{ {
if (GetFileSizeEx(m_hLogFileHandle, &li) && li.LowPart > 0 && li.HighPart == 0) if (GetFileSizeEx(m_hLogFileHandle, &li) && li.LowPart > 0 && li.HighPart == 0)
@ -949,18 +932,16 @@ IN_PROCESS_APPLICATION::LogErrorsOnMainExit(
{ {
if (ReadFile(m_hLogFileHandle, pzFileContents, 4096, &dwNumBytesRead, NULL)) if (ReadFile(m_hLogFileHandle, pzFileContents, 4096, &dwNumBytesRead, NULL))
{ {
if (SUCCEEDED(struStdErrLog.CopyA(m_pzFileContents, m_dwStdErrReadTotal)) && if (SUCCEEDED(struStdErrLog.CopyA(m_pzFileContents, m_dwStdErrReadTotal)))
SUCCEEDED(strEventMsg.SafeSnwprintf( {
UTILITY::LogEventF(g_hEventLog,
EVENTLOG_ERROR_TYPE,
ASPNETCORE_EVENT_INPROCESS_THREAD_EXIT,
ASPNETCORE_EVENT_INPROCESS_THREAD_EXIT_STDOUT_MSG, ASPNETCORE_EVENT_INPROCESS_THREAD_EXIT_STDOUT_MSG,
m_pConfig->QueryApplicationPath()->QueryStr(), m_pConfig->QueryApplicationPath()->QueryStr(),
m_pConfig->QueryApplicationPhysicalPath()->QueryStr(), m_pConfig->QueryApplicationPhysicalPath()->QueryStr(),
hr, hr,
struStdErrLog.QueryStr()))) struStdErrLog.QueryStr());
{
UTILITY::LogEvent(g_hEventLog,
EVENTLOG_ERROR_TYPE,
ASPNETCORE_EVENT_INPROCESS_THREAD_EXIT,
strEventMsg.QueryStr());
fLogged = TRUE; fLogged = TRUE;
} }
@ -973,18 +954,16 @@ IN_PROCESS_APPLICATION::LogErrorsOnMainExit(
{ {
if (m_dwStdErrReadTotal > 0) if (m_dwStdErrReadTotal > 0)
{ {
if (SUCCEEDED(struStdErrLog.CopyA(m_pzFileContents, m_dwStdErrReadTotal)) && if (SUCCEEDED(struStdErrLog.CopyA(m_pzFileContents, m_dwStdErrReadTotal)))
SUCCEEDED(strEventMsg.SafeSnwprintf( {
UTILITY::LogEventF(g_hEventLog,
EVENTLOG_ERROR_TYPE,
ASPNETCORE_EVENT_INPROCESS_THREAD_EXIT,
ASPNETCORE_EVENT_INPROCESS_THREAD_EXIT_STDERR_MSG, ASPNETCORE_EVENT_INPROCESS_THREAD_EXIT_STDERR_MSG,
m_pConfig->QueryApplicationPath()->QueryStr(), m_pConfig->QueryApplicationPath()->QueryStr(),
m_pConfig->QueryApplicationPhysicalPath()->QueryStr(), m_pConfig->QueryApplicationPhysicalPath()->QueryStr(),
hr, hr,
struStdErrLog.QueryStr()))) struStdErrLog.QueryStr());
{
UTILITY::LogEvent(g_hEventLog,
EVENTLOG_ERROR_TYPE,
ASPNETCORE_EVENT_INPROCESS_THREAD_EXIT,
strEventMsg.QueryStr());
fLogged = TRUE; fLogged = TRUE;
} }
} }
@ -993,27 +972,23 @@ IN_PROCESS_APPLICATION::LogErrorsOnMainExit(
if (!fLogged) if (!fLogged)
{ {
// If we didn't log, log the generic message. // If we didn't log, log the generic message.
if (SUCCEEDED(strEventMsg.SafeSnwprintf( UTILITY::LogEventF(g_hEventLog,
EVENTLOG_ERROR_TYPE,
ASPNETCORE_EVENT_INPROCESS_THREAD_EXIT,
ASPNETCORE_EVENT_INPROCESS_THREAD_EXIT_MSG, ASPNETCORE_EVENT_INPROCESS_THREAD_EXIT_MSG,
m_pConfig->QueryApplicationPath()->QueryStr(), m_pConfig->QueryApplicationPath()->QueryStr(),
m_pConfig->QueryApplicationPhysicalPath()->QueryStr(), m_pConfig->QueryApplicationPhysicalPath()->QueryStr(),
hr))) hr);
{ fLogged = TRUE;
UTILITY::LogEvent(g_hEventLog,
EVENTLOG_ERROR_TYPE,
ASPNETCORE_EVENT_INPROCESS_THREAD_EXIT,
strEventMsg.QueryStr());
fLogged = TRUE;
}
} }
} }
// //
// Calls hostfxr_main with the hostfxr and application as arguments. // Calls hostfxr_main with the hostfxr and application as arguments.
// Method should be called with only // Method should be called with only
// Need to have __try / __except in methods that require unwinding. // Need to have __try / __except in methods that require unwinding.
// Note, this will not // Note, this will not
// //
HRESULT HRESULT
IN_PROCESS_APPLICATION::RunDotnetApplication(DWORD argc, CONST PCWSTR* argv, hostfxr_main_fn pProc) IN_PROCESS_APPLICATION::RunDotnetApplication(DWORD argc, CONST PCWSTR* argv, hostfxr_main_fn pProc)
{ {

View File

@ -40,7 +40,7 @@ PROCESS_MANAGER::Initialize(
{ {
SECURITY_ATTRIBUTES saAttr; SECURITY_ATTRIBUTES saAttr;
saAttr.nLength = sizeof(SECURITY_ATTRIBUTES); saAttr.nLength = sizeof(SECURITY_ATTRIBUTES);
saAttr.bInheritHandle = TRUE; saAttr.bInheritHandle = TRUE;
saAttr.lpSecurityDescriptor = NULL; saAttr.lpSecurityDescriptor = NULL;
m_hNULHandle = CreateFileW( L"NUL", m_hNULHandle = CreateFileW( L"NUL",
@ -101,7 +101,7 @@ PROCESS_MANAGER::~PROCESS_MANAGER()
ReleaseSRWLockExclusive(&m_srwLock); ReleaseSRWLockExclusive(&m_srwLock);
} }
HRESULT HRESULT
PROCESS_MANAGER::GetProcess( PROCESS_MANAGER::GetProcess(
_In_ ASPNETCORE_CONFIG *pConfig, _In_ ASPNETCORE_CONFIG *pConfig,
_Out_ SERVER_PROCESS **ppServerProcess _Out_ SERVER_PROCESS **ppServerProcess
@ -110,7 +110,6 @@ PROCESS_MANAGER::GetProcess(
HRESULT hr = S_OK; HRESULT hr = S_OK;
BOOL fSharedLock = FALSE; BOOL fSharedLock = FALSE;
BOOL fExclusiveLock = FALSE; BOOL fExclusiveLock = FALSE;
STACK_STRU(strEventMsg, 256);
DWORD dwProcessIndex = 0; DWORD dwProcessIndex = 0;
SERVER_PROCESS *pSelectedServerProcess = NULL; SERVER_PROCESS *pSelectedServerProcess = NULL;
@ -189,15 +188,11 @@ PROCESS_MANAGER::GetProcess(
// //
// rapid fails per minute exceeded, do not create new process. // rapid fails per minute exceeded, do not create new process.
// //
if (SUCCEEDED(strEventMsg.SafeSnwprintf( UTILITY::LogEventF(g_hEventLog,
EVENTLOG_INFORMATION_TYPE,
ASPNETCORE_EVENT_RAPID_FAIL_COUNT_EXCEEDED,
ASPNETCORE_EVENT_RAPID_FAIL_COUNT_EXCEEDED_MSG, ASPNETCORE_EVENT_RAPID_FAIL_COUNT_EXCEEDED_MSG,
pConfig->QueryRapidFailsPerMinute()))) pConfig->QueryRapidFailsPerMinute());
{
UTILITY::LogEvent(g_hEventLog,
EVENTLOG_INFORMATION_TYPE,
ASPNETCORE_EVENT_RAPID_FAIL_COUNT_EXCEEDED,
strEventMsg.QueryStr());
}
hr = HRESULT_FROM_WIN32(ERROR_SERVER_DISABLED); hr = HRESULT_FROM_WIN32(ERROR_SERVER_DISABLED);
goto Finished; goto Finished;

View File

@ -75,7 +75,7 @@ SERVER_PROCESS::SetupJobObject(VOID)
m_hJobObject = NULL; m_hJobObject = NULL;
// ignore job object creation error. // ignore job object creation error.
} }
#pragma warning( error : 4312) #pragma warning( error : 4312)
if (m_hJobObject != NULL) if (m_hJobObject != NULL)
{ {
jobInfo.BasicLimitInformation.LimitFlags = jobInfo.BasicLimitInformation.LimitFlags =
@ -119,7 +119,7 @@ SERVER_PROCESS::GetRandomPort
do do
{ {
// //
// ignore dwActualProcessId because here we are // ignore dwActualProcessId because here we are
// determing whether the randomly generated port is // determing whether the randomly generated port is
// in use by any other process. // in use by any other process.
// //
@ -144,7 +144,6 @@ SERVER_PROCESS::SetupListenPort(
{ {
HRESULT hr = S_OK; HRESULT hr = S_OK;
ENVIRONMENT_VAR_ENTRY *pEntry = NULL; ENVIRONMENT_VAR_ENTRY *pEntry = NULL;
STACK_STRU(strEventMsg, 256);
*pfCriticalError = FALSE; *pfCriticalError = FALSE;
pEnvironmentVarTable->FindKey(ASPNETCORE_PORT_ENV_STR, &pEntry); pEnvironmentVarTable->FindKey(ASPNETCORE_PORT_ENV_STR, &pEntry);
@ -167,7 +166,7 @@ SERVER_PROCESS::SetupListenPort(
{ {
// //
// user set the env variable but did not give value, let's set it up // user set the env variable but did not give value, let's set it up
// //
pEnvironmentVarTable->DeleteKey(ASPNETCORE_PORT_ENV_STR); pEnvironmentVarTable->DeleteKey(ASPNETCORE_PORT_ENV_STR);
} }
pEntry->Dereference(); pEntry->Dereference();
@ -209,20 +208,16 @@ Finished:
if (FAILED(hr)) if (FAILED(hr))
{ {
if (SUCCEEDED(strEventMsg.SafeSnwprintf( UTILITY::LogEventF(g_hEventLog,
EVENTLOG_ERROR_TYPE,
ASPNETCORE_EVENT_PROCESS_START_SUCCESS,
ASPNETCORE_EVENT_PROCESS_START_PORTSETUP_ERROR_MSG, ASPNETCORE_EVENT_PROCESS_START_PORTSETUP_ERROR_MSG,
m_struAppFullPath.QueryStr(), m_struAppFullPath.QueryStr(),
m_struPhysicalPath.QueryStr(), m_struPhysicalPath.QueryStr(),
m_dwPort, m_dwPort,
MIN_PORT, MIN_PORT,
MAX_PORT, MAX_PORT,
hr))) hr);
{
UTILITY::LogEvent(g_hEventLog,
EVENTLOG_ERROR_TYPE,
ASPNETCORE_EVENT_PROCESS_START_SUCCESS,
strEventMsg.QueryStr());
}
} }
return hr; return hr;
@ -363,10 +358,10 @@ SERVER_PROCESS::OutputEnvironmentVariables
ENVIRONMENT_VAR_ENTRY* pEntry = NULL; ENVIRONMENT_VAR_ENTRY* pEntry = NULL;
DBG_ASSERT(pmszOutput); DBG_ASSERT(pmszOutput);
DBG_ASSERT(pEnvironmentVarTable); // We added some startup variables DBG_ASSERT(pEnvironmentVarTable); // We added some startup variables
DBG_ASSERT(pEnvironmentVarTable->Count() >0); DBG_ASSERT(pEnvironmentVarTable->Count() >0);
// cleanup, as we may in retry logic // cleanup, as we may in retry logic
pmszOutput->Reset(); pmszOutput->Reset();
pszEnvironmentVariables = GetEnvironmentStringsW(); pszEnvironmentVariables = GetEnvironmentStringsW();
@ -625,7 +620,7 @@ SERVER_PROCESS::PostStartCheck(
if(!fProcessMatch) if(!fProcessMatch)
{ {
// //
// process that we created is not listening // process that we created is not listening
// on the port we specified. // on the port we specified.
// //
fReady = FALSE; fReady = FALSE;
@ -667,7 +662,7 @@ SERVER_PROCESS::PostStartCheck(
// This is needed because, the child process might have crashed/exited between // This is needed because, the child process might have crashed/exited between
// the previous call to checkIfServerIsUp and RegisterProcessWait // the previous call to checkIfServerIsUp and RegisterProcessWait
// and we would not know about it. // and we would not know about it.
// //
hr = CheckIfServerIsUp(m_dwPort, &dwActualProcessId, &fReady); hr = CheckIfServerIsUp(m_dwPort, &dwActualProcessId, &fReady);
@ -685,8 +680,8 @@ SERVER_PROCESS::PostStartCheck(
} }
// //
// ready to mark the server process ready but before this, // ready to mark the server process ready but before this,
// create and initialize the FORWARDER_CONNECTION // create and initialize the FORWARDER_CONNECTION
// //
if (m_pForwarderConnection == NULL) if (m_pForwarderConnection == NULL)
{ {
@ -744,7 +739,6 @@ SERVER_PROCESS::StartProcess(
STARTUPINFOW startupInfo = {0}; STARTUPINFOW startupInfo = {0};
DWORD dwRetryCount = 2; // should we allow customer to config it DWORD dwRetryCount = 2; // should we allow customer to config it
DWORD dwCreationFlags = 0; DWORD dwCreationFlags = 0;
STACK_STRU( strEventMsg, 256);
MULTISZ mszNewEnvironment; MULTISZ mszNewEnvironment;
ENVIRONMENT_VAR_HASH *pHashTable = NULL; ENVIRONMENT_VAR_HASH *pHashTable = NULL;
PWSTR pStrStage = NULL; PWSTR pStrStage = NULL;
@ -890,17 +884,13 @@ SERVER_PROCESS::StartProcess(
// Backend process starts successfully. Set retry counter to 0 // Backend process starts successfully. Set retry counter to 0
dwRetryCount = 0; dwRetryCount = 0;
if (SUCCEEDED(strEventMsg.SafeSnwprintf( UTILITY::LogEventF(g_hEventLog,
ASPNETCORE_EVENT_PROCESS_START_SUCCESS_MSG, EVENTLOG_INFORMATION_TYPE,
m_struAppFullPath.QueryStr(), ASPNETCORE_EVENT_PROCESS_START_SUCCESS,
m_dwProcessId, ASPNETCORE_EVENT_PROCESS_START_SUCCESS_MSG,
m_dwPort))) m_struAppFullPath.QueryStr(),
{ m_dwProcessId,
UTILITY::LogEvent(g_hEventLog, m_dwPort);
EVENTLOG_INFORMATION_TYPE,
ASPNETCORE_EVENT_PROCESS_START_SUCCESS,
strEventMsg.QueryStr());
}
goto Finished; goto Finished;
@ -911,21 +901,17 @@ SERVER_PROCESS::StartProcess(
dwRetryCount = 0; dwRetryCount = 0;
} }
if (SUCCEEDED(strEventMsg.SafeSnwprintf( UTILITY::LogEventF(g_hEventLog,
ASPNETCORE_EVENT_PROCESS_START_ERROR_MSG, EVENTLOG_WARNING_TYPE,
m_struAppFullPath.QueryStr(), ASPNETCORE_EVENT_PROCESS_START_ERROR,
m_struPhysicalPath.QueryStr(), ASPNETCORE_EVENT_PROCESS_START_ERROR_MSG,
m_struCommandLine.QueryStr(), m_struAppFullPath.QueryStr(),
pStrStage, m_struPhysicalPath.QueryStr(),
hr, m_struCommandLine.QueryStr(),
m_dwPort, pStrStage,
dwRetryCount))) hr,
{ m_dwPort,
UTILITY::LogEvent(g_hEventLog, dwRetryCount);
EVENTLOG_WARNING_TYPE,
ASPNETCORE_EVENT_PROCESS_START_ERROR,
strEventMsg.QueryStr());
}
if (processInformation.hThread != NULL) if (processInformation.hThread != NULL)
{ {
@ -960,18 +946,14 @@ Finished:
m_Timer.CancelTimer(); m_Timer.CancelTimer();
} }
if (SUCCEEDED(strEventMsg.SafeSnwprintf( UTILITY::LogEventF(g_hEventLog,
EVENTLOG_ERROR_TYPE,
ASPNETCORE_EVENT_PROCESS_START_FAILURE,
ASPNETCORE_EVENT_PROCESS_START_FAILURE_MSG, ASPNETCORE_EVENT_PROCESS_START_FAILURE_MSG,
m_struAppFullPath.QueryStr(), m_struAppFullPath.QueryStr(),
m_struPhysicalPath.QueryStr(), m_struPhysicalPath.QueryStr(),
m_struCommandLine.QueryStr(), m_struCommandLine.QueryStr(),
m_dwPort))) m_dwPort);
{
UTILITY::LogEvent(g_hEventLog,
EVENTLOG_ERROR_TYPE,
ASPNETCORE_EVENT_PROCESS_START_FAILURE,
strEventMsg.QueryStr());
}
} }
return hr; return hr;
} }
@ -1101,17 +1083,12 @@ Finished:
if (m_fStdoutLogEnabled) if (m_fStdoutLogEnabled)
{ {
// Log the error // Log the error
STRU strEventMsg; UTILITY::LogEventF(g_hEventLog,
if (SUCCEEDED(strEventMsg.SafeSnwprintf( EVENTLOG_WARNING_TYPE,
ASPNETCORE_EVENT_CONFIG_ERROR,
ASPNETCORE_EVENT_INVALID_STDOUT_LOG_FILE_MSG, ASPNETCORE_EVENT_INVALID_STDOUT_LOG_FILE_MSG,
m_struFullLogFile.IsEmpty()? m_struLogFile.QueryStr() : m_struFullLogFile.QueryStr(), m_struFullLogFile.IsEmpty()? m_struLogFile.QueryStr() : m_struFullLogFile.QueryStr(),
hr))) hr);
{
UTILITY::LogEvent(g_hEventLog,
EVENTLOG_WARNING_TYPE,
ASPNETCORE_EVENT_CONFIG_ERROR,
strEventMsg.QueryStr());
}
} }
// The log file was not created yet in case of failure. No need to clean it // The log file was not created yet in case of failure. No need to clean it
m_struFullLogFile.Reset(); m_struFullLogFile.Reset();
@ -1264,7 +1241,7 @@ SERVER_PROCESS::SendSignal(
if (m_hShutdownHandle == NULL) if (m_hShutdownHandle == NULL)
{ {
// since we cannot open the process. let's terminate the process // since we cannot open the process. let's terminate the process
hr = HRESULT_FROM_WIN32(GetLastError()); hr = HRESULT_FROM_WIN32(GetLastError());
goto Finished; goto Finished;
} }
@ -1358,7 +1335,7 @@ SERVER_PROCESS::StopProcess(
} }
} }
BOOL BOOL
SERVER_PROCESS::IsDebuggerIsAttached( SERVER_PROCESS::IsDebuggerIsAttached(
VOID VOID
) )
@ -1441,7 +1418,7 @@ SERVER_PROCESS::IsDebuggerIsAttached(
hr = HRESULT_FROM_WIN32(ERROR_CREATE_FAILED); hr = HRESULT_FROM_WIN32(ERROR_CREATE_FAILED);
goto Finished; goto Finished;
} }
for (DWORD i=0; i<processList->NumberOfProcessIdsInList; i++) for (DWORD i=0; i<processList->NumberOfProcessIdsInList; i++)
{ {
dwPid = (DWORD)processList->ProcessIdList[i]; dwPid = (DWORD)processList->ProcessIdList[i];
@ -1481,7 +1458,7 @@ Finished:
return fDebuggerPresent; return fDebuggerPresent;
} }
HRESULT HRESULT
SERVER_PROCESS::GetChildProcessHandles( SERVER_PROCESS::GetChildProcessHandles(
VOID VOID
) )
@ -1560,7 +1537,7 @@ SERVER_PROCESS::GetChildProcessHandles(
hr = HRESULT_FROM_WIN32(ERROR_CREATE_FAILED); hr = HRESULT_FROM_WIN32(ERROR_CREATE_FAILED);
goto Finished; goto Finished;
} }
for (DWORD i=0; i<processList->NumberOfProcessIdsInList; i++) for (DWORD i=0; i<processList->NumberOfProcessIdsInList; i++)
{ {
dwPid = (DWORD)processList->ProcessIdList[i]; dwPid = (DWORD)processList->ProcessIdList[i];
@ -1569,8 +1546,8 @@ SERVER_PROCESS::GetChildProcessHandles(
{ {
m_hChildProcessHandles[m_cChildProcess] = OpenProcess( m_hChildProcessHandles[m_cChildProcess] = OpenProcess(
PROCESS_QUERY_INFORMATION | SYNCHRONIZE | PROCESS_TERMINATE | PROCESS_DUP_HANDLE, PROCESS_QUERY_INFORMATION | SYNCHRONIZE | PROCESS_TERMINATE | PROCESS_DUP_HANDLE,
FALSE, FALSE,
dwPid dwPid
); );
m_dwChildProcessIds[m_cChildProcess] = dwPid; m_dwChildProcessIds[m_cChildProcess] = dwPid;
m_cChildProcess ++; m_cChildProcess ++;
@ -1650,7 +1627,7 @@ SERVER_PROCESS::StopAllProcessesInJobObject(
// some error // some error
goto Finished; goto Finished;
} }
for (DWORD i=0; i<processList->NumberOfProcessIdsInList; i++) for (DWORD i=0; i<processList->NumberOfProcessIdsInList; i++)
{ {
if (dwWorkerProcessPid != (DWORD)processList->ProcessIdList[i]) if (dwWorkerProcessPid != (DWORD)processList->ProcessIdList[i])
@ -1791,7 +1768,7 @@ SERVER_PROCESS::~SERVER_PROCESS()
m_pEnvironmentVarTable = NULL; m_pEnvironmentVarTable = NULL;
// no need to free m_pEnvironmentVarTable, as it references to // no need to free m_pEnvironmentVarTable, as it references to
// the same hash table hold by configuration. // the same hash table hold by configuration.
// the hashtable memory will be freed once onfiguration got recycled // the hashtable memory will be freed once onfiguration got recycled
if (m_pProcessManager != NULL) if (m_pProcessManager != NULL)
{ {
@ -1812,7 +1789,7 @@ SERVER_PROCESS::~SERVER_PROCESS()
{ {
m_Timer.CancelTimer(); m_Timer.CancelTimer();
} }
if (!m_fStdoutLogEnabled && !m_struFullLogFile.IsEmpty()) if (!m_fStdoutLogEnabled && !m_struFullLogFile.IsEmpty())
{ {
WIN32_FIND_DATA fileData; WIN32_FIND_DATA fileData;
@ -1863,7 +1840,7 @@ SERVER_PROCESS::RegisterProcessWait(
(WAITORTIMERCALLBACKFUNC)&ProcessHandleCallback, (WAITORTIMERCALLBACKFUNC)&ProcessHandleCallback,
this, this,
INFINITE, INFINITE,
WT_EXECUTEONLYONCE | WT_EXECUTEINWAITTHREAD WT_EXECUTEONLYONCE | WT_EXECUTEINWAITTHREAD
); );
if (status < 0) if (status < 0)
@ -1917,7 +1894,6 @@ SERVER_PROCESS::SendShutdownHttpMessage( VOID )
STRU strUrl; STRU strUrl;
DWORD dwStatusCode = 0; DWORD dwStatusCode = 0;
DWORD dwSize = sizeof(dwStatusCode); DWORD dwSize = sizeof(dwStatusCode);
STACK_STRU(strEventMsg, 256);
hSession = WinHttpOpen(L"", hSession = WinHttpOpen(L"",
WINHTTP_ACCESS_TYPE_DEFAULT_PROXY, WINHTTP_ACCESS_TYPE_DEFAULT_PROXY,
@ -2020,16 +1996,12 @@ SERVER_PROCESS::SendShutdownHttpMessage( VOID )
} }
// log // log
if (SUCCEEDED(strEventMsg.SafeSnwprintf( UTILITY::LogEventF(g_hEventLog,
EVENTLOG_INFORMATION_TYPE,
ASPNETCORE_EVENT_SENT_SHUTDOWN_HTTP_REQUEST,
ASPNETCORE_EVENT_SENT_SHUTDOWN_HTTP_REQUEST_MSG, ASPNETCORE_EVENT_SENT_SHUTDOWN_HTTP_REQUEST_MSG,
m_dwProcessId, m_dwProcessId,
dwStatusCode))) dwStatusCode);
{
UTILITY::LogEvent(g_hEventLog,
EVENTLOG_INFORMATION_TYPE,
ASPNETCORE_EVENT_SENT_SHUTDOWN_HTTP_REQUEST,
strEventMsg.QueryStr());
}
Finished: Finished:
if (hRequest) if (hRequest)
@ -2120,8 +2092,6 @@ SERVER_PROCESS::TerminateBackendProcess(
VOID VOID
) )
{ {
STACK_STRU(strEventMsg, 256);
if (InterlockedCompareExchange(&m_lStopping, 1L, 0L) == 0L) if (InterlockedCompareExchange(&m_lStopping, 1L, 0L) == 0L)
{ {
// backend process will be terminated, remove the waitcallback // backend process will be terminated, remove the waitcallback
@ -2129,7 +2099,7 @@ SERVER_PROCESS::TerminateBackendProcess(
{ {
UnregisterWait(m_hProcessWaitHandle); UnregisterWait(m_hProcessWaitHandle);
// as we skipped process exit callback (ProcessHandleCallback), // as we skipped process exit callback (ProcessHandleCallback),
// need to dereference the object otherwise memory leak // need to dereference the object otherwise memory leak
DereferenceServerProcess(); DereferenceServerProcess();
@ -2144,14 +2114,10 @@ SERVER_PROCESS::TerminateBackendProcess(
} }
// log a warning for ungraceful shutdown // log a warning for ungraceful shutdown
if (SUCCEEDED(strEventMsg.SafeSnwprintf( UTILITY::LogEventF(g_hEventLog,
EVENTLOG_WARNING_TYPE,
ASPNETCORE_EVENT_GRACEFUL_SHUTDOWN_FAILURE,
ASPNETCORE_EVENT_GRACEFUL_SHUTDOWN_FAILURE_MSG, ASPNETCORE_EVENT_GRACEFUL_SHUTDOWN_FAILURE_MSG,
m_dwProcessId))) m_dwProcessId);
{
UTILITY::LogEvent(g_hEventLog,
EVENTLOG_WARNING_TYPE,
ASPNETCORE_EVENT_GRACEFUL_SHUTDOWN_FAILURE,
strEventMsg.QueryStr());
}
} }
} }