Use HandleWrapper and initialize variables for FileOutputManager (#986)

This commit is contained in:
Justin Kotalik 2018-06-28 09:09:34 -07:00 committed by GitHub
parent 27780c28ba
commit 4a09d4795e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 36 additions and 16 deletions

View File

@ -216,6 +216,7 @@
<ClCompile Include="debugutil.cpp" /> <ClCompile Include="debugutil.cpp" />
<ClCompile Include="fx_ver.cxx" /> <ClCompile Include="fx_ver.cxx" />
<ClCompile Include="GlobalVersionUtility.cpp" /> <ClCompile Include="GlobalVersionUtility.cpp" />
<ClCompile Include="HandleWrapper.cpp" />
<ClCompile Include="hostfxr_utility.cpp" /> <ClCompile Include="hostfxr_utility.cpp" />
<ClCompile Include="hostfxroptions.cpp" /> <ClCompile Include="hostfxroptions.cpp" />
<ClCompile Include="SRWExclusiveLock.cpp" /> <ClCompile Include="SRWExclusiveLock.cpp" />

View File

@ -0,0 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#include "HandleWrapper.h"
// Workaround for VC++ bug https://developercommunity.visualstudio.com/content/problem/33928/constexpr-failing-on-nullptr-v141-compiler-regress.html
const HANDLE InvalidHandleTraits::DefaultHandle = INVALID_HANDLE_VALUE;

View File

@ -12,9 +12,6 @@ struct InvalidHandleTraits
static void Close(HANDLE handle) { CloseHandle(handle); } static void Close(HANDLE handle) { CloseHandle(handle); }
}; };
// Workaround for VC++ bug https://developercommunity.visualstudio.com/content/problem/33928/constexpr-failing-on-nullptr-v141-compiler-regress.html
const HANDLE InvalidHandleTraits::DefaultHandle = INVALID_HANDLE_VALUE;
struct NullHandleTraits struct NullHandleTraits
{ {
using HandleType = HANDLE; using HandleType = HANDLE;

View File

@ -11,6 +11,7 @@
#include "EventLog.h" #include "EventLog.h"
#include "SRWExclusiveLock.h" #include "SRWExclusiveLock.h"
#include "exceptions.h" #include "exceptions.h"
#include "LoggingHelpers.h"
IN_PROCESS_APPLICATION* IN_PROCESS_APPLICATION::s_Application = NULL; IN_PROCESS_APPLICATION* IN_PROCESS_APPLICATION::s_Application = NULL;

View File

@ -7,7 +7,7 @@
#include "InProcessApplicationBase.h" #include "InProcessApplicationBase.h"
#include "inprocesshandler.h" #include "inprocesshandler.h"
#include "requesthandler_config.h" #include "requesthandler_config.h"
#include "IOutputManager.h"
typedef REQUEST_NOTIFICATION_STATUS(WINAPI * PFN_REQUEST_HANDLER) (IN_PROCESS_HANDLER* pInProcessHandler, void* pvRequestHandlerContext); typedef REQUEST_NOTIFICATION_STATUS(WINAPI * PFN_REQUEST_HANDLER) (IN_PROCESS_HANDLER* pInProcessHandler, void* pvRequestHandlerContext);
typedef BOOL(WINAPI * PFN_SHUTDOWN_HANDLER) (void* pvShutdownHandlerContext); typedef BOOL(WINAPI * PFN_SHUTDOWN_HANDLER) (void* pvShutdownHandlerContext);

View File

@ -4,6 +4,7 @@
#include "inprocesshandler.h" #include "inprocesshandler.h"
#include "inprocessapplication.h" #include "inprocessapplication.h"
#include "aspnetcore_event.h" #include "aspnetcore_event.h"
#include "IOutputManager.h"
ALLOC_CACHE_HANDLER * IN_PROCESS_HANDLER::sm_pAlloc = NULL; ALLOC_CACHE_HANDLER * IN_PROCESS_HANDLER::sm_pAlloc = NULL;

View File

@ -2,12 +2,16 @@
// Licensed under the MIT License. See License.txt in the project root for license information. // Licensed under the MIT License. See License.txt in the project root for license information.
#include "stdafx.h" #include "stdafx.h"
#include "FileOutputManager.h"
#include "sttimer.h" #include "sttimer.h"
#include "utility.h" #include "utility.h"
#include "exceptions.h" #include "exceptions.h"
#include "debugutil.h" #include "debugutil.h"
FileOutputManager::FileOutputManager() FileOutputManager::FileOutputManager() :
m_hLogFileHandle(INVALID_HANDLE_VALUE),
m_fdPreviousStdOut(0),
m_fdPreviousStdErr(0)
{ {
} }
@ -19,8 +23,6 @@ FileOutputManager::~FileOutputManager()
if (m_hLogFileHandle != INVALID_HANDLE_VALUE) if (m_hLogFileHandle != INVALID_HANDLE_VALUE)
{ {
m_Timer.CancelTimer(); m_Timer.CancelTimer();
CloseHandle(m_hLogFileHandle);
m_hLogFileHandle = INVALID_HANDLE_VALUE;
} }
// delete empty log file // delete empty log file
@ -122,6 +124,7 @@ FileOutputManager::Start()
RETURN_IF_FAILED(UTILITY::EnsureDirectoryPathExist(struPath.QueryStr())); RETURN_IF_FAILED(UTILITY::EnsureDirectoryPathExist(struPath.QueryStr()));
GetSystemTime(&systemTime); GetSystemTime(&systemTime);
RETURN_IF_FAILED( RETURN_IF_FAILED(
m_struLogFilePath.SafeSnwprintf(L"%s_%d%02d%02d%02d%02d%02d_%d.log", m_struLogFilePath.SafeSnwprintf(L"%s_%d%02d%02d%02d%02d%02d_%d.log",
struPath.QueryStr(), struPath.QueryStr(),

View File

@ -4,6 +4,8 @@
#pragma once #pragma once
#include "sttimer.h" #include "sttimer.h"
#include "IOutputManager.h"
#include "HandleWrapper.h"
class FileOutputManager : public IOutputManager class FileOutputManager : public IOutputManager
{ {
@ -20,7 +22,7 @@ public:
virtual void NotifyStartupComplete() override; virtual void NotifyStartupComplete() override;
private: private:
HANDLE m_hLogFileHandle; HandleWrapper<InvalidHandleTraits> m_hLogFileHandle;
STTIMER m_Timer; STTIMER m_Timer;
STRU m_wsStdOutLogFileName; STRU m_wsStdOutLogFileName;
STRU m_wsApplicationPath; STRU m_wsApplicationPath;

View File

@ -2,6 +2,11 @@
// Licensed under the MIT License. See License.txt in the project root for license information. // Licensed under the MIT License. See License.txt in the project root for license information.
#include "stdafx.h" #include "stdafx.h"
#include "LoggingHelpers.h"
#include "IOutputManager.h"
#include "FileOutputManager.h"
#include "PipeOutputManager.h"
#include "NullOutputManager.h"
HRESULT HRESULT
LoggingHelpers::CreateLoggingProvider( LoggingHelpers::CreateLoggingProvider(

View File

@ -3,6 +3,8 @@
#pragma once #pragma once
#include "IOutputManager.h"
class LoggingHelpers class LoggingHelpers
{ {
public: public:

View File

@ -2,6 +2,7 @@
// Licensed under the MIT License. See License.txt in the project root for license information. // Licensed under the MIT License. See License.txt in the project root for license information.
#include "stdafx.h" #include "stdafx.h"
#include "PipeOutputManager.h"
#include "exceptions.h" #include "exceptions.h"
#include "SRWExclusiveLock.h" #include "SRWExclusiveLock.h"

View File

@ -3,6 +3,8 @@
#pragma once #pragma once
#include "IOutputManager.h"
class PipeOutputManager : public IOutputManager class PipeOutputManager : public IOutputManager
{ {
#define PIPE_OUTPUT_THREAD_TIMEOUT 2000 #define PIPE_OUTPUT_THREAD_TIMEOUT 2000

View File

@ -4,6 +4,7 @@
#include "stdafx.h" #include "stdafx.h"
#include "requesthandler_config.h" #include "requesthandler_config.h"
#include "debugutil.h" #include "debugutil.h"
#include "environmentvariablehash.h"
REQUESTHANDLER_CONFIG::~REQUESTHANDLER_CONFIG() REQUESTHANDLER_CONFIG::~REQUESTHANDLER_CONFIG()
{ {

View File

@ -42,6 +42,7 @@
//#define HEX_TO_ASCII(c) ((CHAR)(((c) < 10) ? ((c) + '0') : ((c) + 'a' - 10))) //#define HEX_TO_ASCII(c) ((CHAR)(((c) < 10) ? ((c) + '0') : ((c) + 'a' - 10)))
#include "stdafx.h" #include "stdafx.h"
#include "environmentvariablehash.h"
enum APP_HOSTING_MODEL enum APP_HOSTING_MODEL
{ {

View File

@ -16,6 +16,7 @@
#include "Shlwapi.h" #include "Shlwapi.h"
#include <io.h> #include <io.h>
#include "hashtable.h" #include "hashtable.h"
#include "stringu.h" #include "stringu.h"
#include "stringa.h" #include "stringa.h"
@ -23,10 +24,5 @@
#include "dbgutil.h" #include "dbgutil.h"
#include "ahutil.h" #include "ahutil.h"
#include "hashfn.h" #include "hashfn.h"
#include "environmentvariablehash.h"
#include "IOutputManager.h"
#include "FileOutputManager.h"
#include "PipeOutputManager.h"
#include "NullOutputManager.h"
#include "LoggingHelpers.h"

View File

@ -3,6 +3,7 @@
#include "stdafx.h" #include "stdafx.h"
#include "gtest/internal/gtest-port.h" #include "gtest/internal/gtest-port.h"
#include "FileOutputManager.h"
class FileManagerWrapper class FileManagerWrapper
{ {

View File

@ -3,6 +3,7 @@
#include "stdafx.h" #include "stdafx.h"
#include "gtest/internal/gtest-port.h" #include "gtest/internal/gtest-port.h"
#include "PipeOutputManager.h"
class FileManagerWrapper class FileManagerWrapper
{ {

View File

@ -58,5 +58,3 @@
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "fakeclasses.h" #include "fakeclasses.h"
\