From 4a09d4795e5c21eef3e07a7eb76d348a5c7a1617 Mon Sep 17 00:00:00 2001 From: Justin Kotalik Date: Thu, 28 Jun 2018 09:09:34 -0700 Subject: [PATCH] Use HandleWrapper and initialize variables for FileOutputManager (#986) --- src/AspNetCoreModuleV2/CommonLib/CommonLib.vcxproj | 1 + src/AspNetCoreModuleV2/CommonLib/HandleWrapper.cpp | 7 +++++++ src/AspNetCoreModuleV2/CommonLib/HandleWrapper.h | 3 --- .../InProcessRequestHandler/inprocessapplication.cpp | 1 + .../InProcessRequestHandler/inprocessapplication.h | 2 +- .../InProcessRequestHandler/inprocesshandler.cpp | 1 + .../RequestHandlerLib/FileOutputManager.cpp | 9 ++++++--- .../RequestHandlerLib/FileOutputManager.h | 4 +++- .../RequestHandlerLib/LoggingHelpers.cpp | 5 +++++ .../RequestHandlerLib/LoggingHelpers.h | 2 ++ .../RequestHandlerLib/PipeOutputManager.cpp | 1 + .../RequestHandlerLib/PipeOutputManager.h | 2 ++ .../RequestHandlerLib/requesthandler_config.cpp | 1 + .../RequestHandlerLib/requesthandler_config.h | 1 + src/AspNetCoreModuleV2/RequestHandlerLib/stdafx.h | 8 ++------ test/CommonLibTests/FileOutputManagerTests.cpp | 1 + test/CommonLibTests/PipeOutputManagerTests.cpp | 1 + test/CommonLibTests/stdafx.h | 2 -- 18 files changed, 36 insertions(+), 16 deletions(-) create mode 100644 src/AspNetCoreModuleV2/CommonLib/HandleWrapper.cpp diff --git a/src/AspNetCoreModuleV2/CommonLib/CommonLib.vcxproj b/src/AspNetCoreModuleV2/CommonLib/CommonLib.vcxproj index 4ba17f46db..b40c09583c 100644 --- a/src/AspNetCoreModuleV2/CommonLib/CommonLib.vcxproj +++ b/src/AspNetCoreModuleV2/CommonLib/CommonLib.vcxproj @@ -216,6 +216,7 @@ + diff --git a/src/AspNetCoreModuleV2/CommonLib/HandleWrapper.cpp b/src/AspNetCoreModuleV2/CommonLib/HandleWrapper.cpp new file mode 100644 index 0000000000..fde7d2fd1f --- /dev/null +++ b/src/AspNetCoreModuleV2/CommonLib/HandleWrapper.cpp @@ -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; diff --git a/src/AspNetCoreModuleV2/CommonLib/HandleWrapper.h b/src/AspNetCoreModuleV2/CommonLib/HandleWrapper.h index 635d37cf4d..67f980dfd4 100644 --- a/src/AspNetCoreModuleV2/CommonLib/HandleWrapper.h +++ b/src/AspNetCoreModuleV2/CommonLib/HandleWrapper.h @@ -12,9 +12,6 @@ struct InvalidHandleTraits 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 { using HandleType = HANDLE; diff --git a/src/AspNetCoreModuleV2/InProcessRequestHandler/inprocessapplication.cpp b/src/AspNetCoreModuleV2/InProcessRequestHandler/inprocessapplication.cpp index 289f587173..85897d906c 100644 --- a/src/AspNetCoreModuleV2/InProcessRequestHandler/inprocessapplication.cpp +++ b/src/AspNetCoreModuleV2/InProcessRequestHandler/inprocessapplication.cpp @@ -11,6 +11,7 @@ #include "EventLog.h" #include "SRWExclusiveLock.h" #include "exceptions.h" +#include "LoggingHelpers.h" IN_PROCESS_APPLICATION* IN_PROCESS_APPLICATION::s_Application = NULL; diff --git a/src/AspNetCoreModuleV2/InProcessRequestHandler/inprocessapplication.h b/src/AspNetCoreModuleV2/InProcessRequestHandler/inprocessapplication.h index c0932d87a0..6b3bfd18a0 100644 --- a/src/AspNetCoreModuleV2/InProcessRequestHandler/inprocessapplication.h +++ b/src/AspNetCoreModuleV2/InProcessRequestHandler/inprocessapplication.h @@ -7,7 +7,7 @@ #include "InProcessApplicationBase.h" #include "inprocesshandler.h" #include "requesthandler_config.h" - +#include "IOutputManager.h" typedef REQUEST_NOTIFICATION_STATUS(WINAPI * PFN_REQUEST_HANDLER) (IN_PROCESS_HANDLER* pInProcessHandler, void* pvRequestHandlerContext); typedef BOOL(WINAPI * PFN_SHUTDOWN_HANDLER) (void* pvShutdownHandlerContext); diff --git a/src/AspNetCoreModuleV2/InProcessRequestHandler/inprocesshandler.cpp b/src/AspNetCoreModuleV2/InProcessRequestHandler/inprocesshandler.cpp index 98ec620367..5daf8d3604 100644 --- a/src/AspNetCoreModuleV2/InProcessRequestHandler/inprocesshandler.cpp +++ b/src/AspNetCoreModuleV2/InProcessRequestHandler/inprocesshandler.cpp @@ -4,6 +4,7 @@ #include "inprocesshandler.h" #include "inprocessapplication.h" #include "aspnetcore_event.h" +#include "IOutputManager.h" ALLOC_CACHE_HANDLER * IN_PROCESS_HANDLER::sm_pAlloc = NULL; diff --git a/src/AspNetCoreModuleV2/RequestHandlerLib/FileOutputManager.cpp b/src/AspNetCoreModuleV2/RequestHandlerLib/FileOutputManager.cpp index 28d3c47884..3242f96227 100644 --- a/src/AspNetCoreModuleV2/RequestHandlerLib/FileOutputManager.cpp +++ b/src/AspNetCoreModuleV2/RequestHandlerLib/FileOutputManager.cpp @@ -2,12 +2,16 @@ // Licensed under the MIT License. See License.txt in the project root for license information. #include "stdafx.h" +#include "FileOutputManager.h" #include "sttimer.h" #include "utility.h" #include "exceptions.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) { m_Timer.CancelTimer(); - CloseHandle(m_hLogFileHandle); - m_hLogFileHandle = INVALID_HANDLE_VALUE; } // delete empty log file @@ -122,6 +124,7 @@ FileOutputManager::Start() RETURN_IF_FAILED(UTILITY::EnsureDirectoryPathExist(struPath.QueryStr())); GetSystemTime(&systemTime); + RETURN_IF_FAILED( m_struLogFilePath.SafeSnwprintf(L"%s_%d%02d%02d%02d%02d%02d_%d.log", struPath.QueryStr(), diff --git a/src/AspNetCoreModuleV2/RequestHandlerLib/FileOutputManager.h b/src/AspNetCoreModuleV2/RequestHandlerLib/FileOutputManager.h index 184a935596..7f44d92462 100644 --- a/src/AspNetCoreModuleV2/RequestHandlerLib/FileOutputManager.h +++ b/src/AspNetCoreModuleV2/RequestHandlerLib/FileOutputManager.h @@ -4,6 +4,8 @@ #pragma once #include "sttimer.h" +#include "IOutputManager.h" +#include "HandleWrapper.h" class FileOutputManager : public IOutputManager { @@ -20,7 +22,7 @@ public: virtual void NotifyStartupComplete() override; private: - HANDLE m_hLogFileHandle; + HandleWrapper m_hLogFileHandle; STTIMER m_Timer; STRU m_wsStdOutLogFileName; STRU m_wsApplicationPath; diff --git a/src/AspNetCoreModuleV2/RequestHandlerLib/LoggingHelpers.cpp b/src/AspNetCoreModuleV2/RequestHandlerLib/LoggingHelpers.cpp index 2af111253e..a133172db4 100644 --- a/src/AspNetCoreModuleV2/RequestHandlerLib/LoggingHelpers.cpp +++ b/src/AspNetCoreModuleV2/RequestHandlerLib/LoggingHelpers.cpp @@ -2,6 +2,11 @@ // Licensed under the MIT License. See License.txt in the project root for license information. #include "stdafx.h" +#include "LoggingHelpers.h" +#include "IOutputManager.h" +#include "FileOutputManager.h" +#include "PipeOutputManager.h" +#include "NullOutputManager.h" HRESULT LoggingHelpers::CreateLoggingProvider( diff --git a/src/AspNetCoreModuleV2/RequestHandlerLib/LoggingHelpers.h b/src/AspNetCoreModuleV2/RequestHandlerLib/LoggingHelpers.h index fb3f55954f..f11a4ff5f5 100644 --- a/src/AspNetCoreModuleV2/RequestHandlerLib/LoggingHelpers.h +++ b/src/AspNetCoreModuleV2/RequestHandlerLib/LoggingHelpers.h @@ -3,6 +3,8 @@ #pragma once +#include "IOutputManager.h" + class LoggingHelpers { public: diff --git a/src/AspNetCoreModuleV2/RequestHandlerLib/PipeOutputManager.cpp b/src/AspNetCoreModuleV2/RequestHandlerLib/PipeOutputManager.cpp index 8a0cd0074d..5620572c6f 100644 --- a/src/AspNetCoreModuleV2/RequestHandlerLib/PipeOutputManager.cpp +++ b/src/AspNetCoreModuleV2/RequestHandlerLib/PipeOutputManager.cpp @@ -2,6 +2,7 @@ // Licensed under the MIT License. See License.txt in the project root for license information. #include "stdafx.h" +#include "PipeOutputManager.h" #include "exceptions.h" #include "SRWExclusiveLock.h" diff --git a/src/AspNetCoreModuleV2/RequestHandlerLib/PipeOutputManager.h b/src/AspNetCoreModuleV2/RequestHandlerLib/PipeOutputManager.h index f51688197c..9a9b306700 100644 --- a/src/AspNetCoreModuleV2/RequestHandlerLib/PipeOutputManager.h +++ b/src/AspNetCoreModuleV2/RequestHandlerLib/PipeOutputManager.h @@ -3,6 +3,8 @@ #pragma once +#include "IOutputManager.h" + class PipeOutputManager : public IOutputManager { #define PIPE_OUTPUT_THREAD_TIMEOUT 2000 diff --git a/src/AspNetCoreModuleV2/RequestHandlerLib/requesthandler_config.cpp b/src/AspNetCoreModuleV2/RequestHandlerLib/requesthandler_config.cpp index 9a9a5cdd46..4f5a253f9e 100644 --- a/src/AspNetCoreModuleV2/RequestHandlerLib/requesthandler_config.cpp +++ b/src/AspNetCoreModuleV2/RequestHandlerLib/requesthandler_config.cpp @@ -4,6 +4,7 @@ #include "stdafx.h" #include "requesthandler_config.h" #include "debugutil.h" +#include "environmentvariablehash.h" REQUESTHANDLER_CONFIG::~REQUESTHANDLER_CONFIG() { diff --git a/src/AspNetCoreModuleV2/RequestHandlerLib/requesthandler_config.h b/src/AspNetCoreModuleV2/RequestHandlerLib/requesthandler_config.h index 60cbd7c8b7..a7369ca0e7 100644 --- a/src/AspNetCoreModuleV2/RequestHandlerLib/requesthandler_config.h +++ b/src/AspNetCoreModuleV2/RequestHandlerLib/requesthandler_config.h @@ -42,6 +42,7 @@ //#define HEX_TO_ASCII(c) ((CHAR)(((c) < 10) ? ((c) + '0') : ((c) + 'a' - 10))) #include "stdafx.h" +#include "environmentvariablehash.h" enum APP_HOSTING_MODEL { diff --git a/src/AspNetCoreModuleV2/RequestHandlerLib/stdafx.h b/src/AspNetCoreModuleV2/RequestHandlerLib/stdafx.h index 094c71d0cd..96c3ffe6de 100644 --- a/src/AspNetCoreModuleV2/RequestHandlerLib/stdafx.h +++ b/src/AspNetCoreModuleV2/RequestHandlerLib/stdafx.h @@ -16,6 +16,7 @@ #include "Shlwapi.h" #include + #include "hashtable.h" #include "stringu.h" #include "stringa.h" @@ -23,10 +24,5 @@ #include "dbgutil.h" #include "ahutil.h" #include "hashfn.h" -#include "environmentvariablehash.h" -#include "IOutputManager.h" -#include "FileOutputManager.h" -#include "PipeOutputManager.h" -#include "NullOutputManager.h" -#include "LoggingHelpers.h" + diff --git a/test/CommonLibTests/FileOutputManagerTests.cpp b/test/CommonLibTests/FileOutputManagerTests.cpp index 93557c73a3..d0caa524a8 100644 --- a/test/CommonLibTests/FileOutputManagerTests.cpp +++ b/test/CommonLibTests/FileOutputManagerTests.cpp @@ -3,6 +3,7 @@ #include "stdafx.h" #include "gtest/internal/gtest-port.h" +#include "FileOutputManager.h" class FileManagerWrapper { diff --git a/test/CommonLibTests/PipeOutputManagerTests.cpp b/test/CommonLibTests/PipeOutputManagerTests.cpp index 1b16f470d1..e15fa2868a 100644 --- a/test/CommonLibTests/PipeOutputManagerTests.cpp +++ b/test/CommonLibTests/PipeOutputManagerTests.cpp @@ -3,6 +3,7 @@ #include "stdafx.h" #include "gtest/internal/gtest-port.h" +#include "PipeOutputManager.h" class FileManagerWrapper { diff --git a/test/CommonLibTests/stdafx.h b/test/CommonLibTests/stdafx.h index 74af866aa7..33d3008f40 100644 --- a/test/CommonLibTests/stdafx.h +++ b/test/CommonLibTests/stdafx.h @@ -58,5 +58,3 @@ #include "gtest/gtest.h" #include "fakeclasses.h" -\ -