From bf87c539fd85992bc32a550cf04ae537e762ea6b Mon Sep 17 00:00:00 2001 From: Bill Zissimopoulos Date: Thu, 13 Apr 2017 21:57:07 -0700 Subject: [PATCH] inc: winfsp.hpp: Service class improvements --- inc/winfsp/winfsp.hpp | 40 +++++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/inc/winfsp/winfsp.hpp b/inc/winfsp/winfsp.hpp index e6fbc6ce..815da3e9 100644 --- a/inc/winfsp/winfsp.hpp +++ b/inc/winfsp/winfsp.hpp @@ -953,11 +953,12 @@ class Service { public: /* ctor/dtor */ - Service(PWSTR ServiceName) : _Service(0), _CreateResult() + Service(PWSTR ServiceName) : _Service(0) { Initialize(); - _CreateResult = FspServiceCreate(ServiceName, OnStart, OnStop, 0, &_Service); - _Service->UserContext = this; + FspServiceCreate(ServiceName, OnStart, OnStop, 0, &_Service); + if (0 != _Service) + _Service->UserContext = this; } virtual ~Service() { @@ -968,11 +969,12 @@ public: /* control */ ULONG Run() { - if (!NT_SUCCESS(_CreateResult)) + if (0 == _Service) { FspServiceLog(EVENTLOG_ERROR_TYPE, - L"The service cannot be created (Status=%lx).", _CreateResult); - return FspWin32FromNtStatus(_CreateResult); + L"The service cannot be created (Status=%lx).", + STATUS_INSUFFICIENT_RESOURCES); + return FspWin32FromNtStatus(STATUS_INSUFFICIENT_RESOURCES); } FspServiceAllowConsoleMode(_Service); NTSTATUS Result = FspServiceLoop(_Service); @@ -980,17 +982,38 @@ public: if (!NT_SUCCESS(Result)) { FspServiceLog(EVENTLOG_ERROR_TYPE, - L"The service %s has failed to run (Status=%lx).", _Service->ServiceName, Result); + L"The service has failed to run (Status=%lx).", + Result); return FspWin32FromNtStatus(Result); } return ExitCode; } VOID Stop() { - if (!NT_SUCCESS(_CreateResult)) + if (0 == _Service) return; FspServiceStop(_Service); } + VOID RequestTime(ULONG Time) + { + if (0 == _Service) + return; + FspServiceRequestTime(_Service, Time); + } + ULONG GetExitCode() + { + return 0 != _Service ? FspServiceGetExitCode(_Service) : ERROR_NO_SYSTEM_RESOURCES; + } + VOID SetExitCode(ULONG ExitCode) + { + if (0 == _Service) + return; + FspServiceSetExitCode(_Service, ExitCode); + } + FSP_SERVICE *ServiceHandle() + { + return _Service; + } static VOID Log(ULONG Type, PWSTR Format, ...) { va_list ap; @@ -1042,7 +1065,6 @@ private: private: FSP_SERVICE *_Service; - NTSTATUS _CreateResult; }; }