aboutsummaryrefslogtreecommitdiff
path: root/zenserver/windows/service.cpp
diff options
context:
space:
mode:
authorPer Larsson <[email protected]>2021-09-28 15:09:15 +0200
committerPer Larsson <[email protected]>2021-09-28 15:09:15 +0200
commit141317786f9d59e95da8316ce40cf30e4dfd7b53 (patch)
tree3c863384c6ca68a30e82989994408c5f40159273 /zenserver/windows/service.cpp
parentRemoved using the bucket name to detect binary cache records and store conten... (diff)
parentapply: Re-enabled environment variable setup for child processes (diff)
downloadzen-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.cpp33
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;
}