fixing empty logfile name in event log (#602)

Empty log file path was logged as we reset the stru too earlier. Changing the code order
This commit is contained in:
pan-wang 2018-02-21 14:08:26 -08:00 committed by GitHub
parent 21b1febf2b
commit 782b563a58
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 10 deletions

View File

@ -926,6 +926,7 @@ Finished:
if (SUCCEEDED(strEventMsg.SafeSnwprintf( if (SUCCEEDED(strEventMsg.SafeSnwprintf(
ASPNETCORE_EVENT_PROCESS_START_FAILURE_MSG, ASPNETCORE_EVENT_PROCESS_START_FAILURE_MSG,
m_struAppFullPath.QueryStr(), m_struAppFullPath.QueryStr(),
m_struPhysicalPath.QueryStr(),
m_struCommandLine.QueryStr(), m_struCommandLine.QueryStr(),
m_dwPort))) m_dwPort)))
{ {
@ -998,12 +999,6 @@ SERVER_PROCESS::SetupStdHandles(
goto Finished; goto Finished;
} }
hr = UTILITY::EnsureDirectoryPathExist(struPath.QueryStr());
if (FAILED(hr))
{
goto Finished;
}
GetSystemTime(&systemTime); GetSystemTime(&systemTime);
hr = m_struFullLogFile.SafeSnwprintf(L"%s_%d%02d%02d%02d%02d%02d_%d.log", hr = m_struFullLogFile.SafeSnwprintf(L"%s_%d%02d%02d%02d%02d%02d_%d.log",
struPath.QueryStr(), struPath.QueryStr(),
@ -1019,6 +1014,12 @@ SERVER_PROCESS::SetupStdHandles(
goto Finished; goto Finished;
} }
hr = UTILITY::EnsureDirectoryPathExist(struPath.QueryStr());
if (FAILED(hr))
{
goto Finished;
}
saAttr.nLength = sizeof(SECURITY_ATTRIBUTES); saAttr.nLength = sizeof(SECURITY_ATTRIBUTES);
saAttr.bInheritHandle = TRUE; saAttr.bInheritHandle = TRUE;
saAttr.lpSecurityDescriptor = NULL; saAttr.lpSecurityDescriptor = NULL;
@ -1057,8 +1058,6 @@ SERVER_PROCESS::SetupStdHandles(
Finished: Finished:
if (FAILED(hr)) if (FAILED(hr))
{ {
// The log file was not created yet in case of failure. No need to clean it
m_struFullLogFile.Reset();
pStartupInfo->dwFlags = STARTF_USESTDHANDLES; pStartupInfo->dwFlags = STARTF_USESTDHANDLES;
pStartupInfo->hStdInput = INVALID_HANDLE_VALUE; pStartupInfo->hStdInput = INVALID_HANDLE_VALUE;
pStartupInfo->hStdError = INVALID_HANDLE_VALUE; pStartupInfo->hStdError = INVALID_HANDLE_VALUE;
@ -1070,7 +1069,7 @@ Finished:
STRU strEventMsg; STRU strEventMsg;
if (SUCCEEDED(strEventMsg.SafeSnwprintf( if (SUCCEEDED(strEventMsg.SafeSnwprintf(
ASPNETCORE_EVENT_INVALID_STDOUT_LOG_FILE_MSG, ASPNETCORE_EVENT_INVALID_STDOUT_LOG_FILE_MSG,
m_struFullLogFile.QueryStr(), m_struFullLogFile.IsEmpty()? m_struLogFile.QueryStr() : m_struFullLogFile.QueryStr(),
hr))) hr)))
{ {
UTILITY::LogEvent(g_hEventLog, UTILITY::LogEvent(g_hEventLog,
@ -1079,6 +1078,8 @@ Finished:
strEventMsg.QueryStr()); strEventMsg.QueryStr());
} }
} }
// The log file was not created yet in case of failure. No need to clean it
m_struFullLogFile.Reset();
} }
return hr; return hr;
} }