diff options
| author | Per Larsson <[email protected]> | 2021-09-28 15:09:15 +0200 |
|---|---|---|
| committer | Per Larsson <[email protected]> | 2021-09-28 15:09:15 +0200 |
| commit | 141317786f9d59e95da8316ce40cf30e4dfd7b53 (patch) | |
| tree | 3c863384c6ca68a30e82989994408c5f40159273 /zenserver/windows/service.cpp | |
| parent | Removed using the bucket name to detect binary cache records and store conten... (diff) | |
| parent | apply: Re-enabled environment variable setup for child processes (diff) | |
| download | zen-141317786f9d59e95da8316ce40cf30e4dfd7b53.tar.xz zen-141317786f9d59e95da8316ce40cf30e4dfd7b53.zip | |
Merge branch 'main' of https://github.com/EpicGames/zen
Diffstat (limited to 'zenserver/windows/service.cpp')
| -rw-r--r-- | zenserver/windows/service.cpp | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/zenserver/windows/service.cpp b/zenserver/windows/service.cpp index 017b5f9a7..b7b3b9bc1 100644 --- a/zenserver/windows/service.cpp +++ b/zenserver/windows/service.cpp @@ -3,6 +3,7 @@ #include "service.h" #include <zencore/zencore.h> +#include <zencore/except.h> #include <stdio.h> #include <tchar.h> @@ -146,26 +147,34 @@ CallMain(DWORD, LPSTR*) int WindowsService::ServiceMain() { - if (zen::IsInteractiveSession()) - { - // Not actually running as a service - return Run(); - } - else + gSvc = this; + + SERVICE_TABLE_ENTRY DispatchTable[] = {{(LPWSTR)SVCNAME, (LPSERVICE_MAIN_FUNCTION)&CallMain}, {NULL, NULL}}; + + // This call returns when the service has stopped. + // The process should simply terminate when the call returns. + + if (!StartServiceCtrlDispatcher(DispatchTable)) { - gSvc = this; + const DWORD dwError = zen::GetLastError(); - SERVICE_TABLE_ENTRY DispatchTable[] = {{(LPWSTR)SVCNAME, (LPSERVICE_MAIN_FUNCTION)&CallMain}, {NULL, NULL}}; + if (dwError == ERROR_FAILED_SERVICE_CONTROLLER_CONNECT) + { + // Not actually running as a service + gSvc = nullptr; - // This call returns when the service has stopped. - // The process should simply terminate when the call returns. + zen::SetIsInteractiveSession(true); - if (!StartServiceCtrlDispatcher(DispatchTable)) + return Run(); + } + else { - SvcReportEvent((LPTSTR)L"StartServiceCtrlDispatcher"); + zen::ThrowSystemError(dwError, "StartServiceCtrlDispatcher failed"); } } + zen::SetIsInteractiveSession(false); + return 0; } |