diff options
| author | Stefan Boberg <[email protected]> | 2026-04-23 18:16:57 +0200 |
|---|---|---|
| committer | Stefan Boberg <[email protected]> | 2026-04-23 18:16:57 +0200 |
| commit | 0232b991cd7d8e3a2114ea30e4591dd3e7b65c36 (patch) | |
| tree | 94730e7594fd09ae1fa820391ce311f6daf13905 /src/zenutil/windows | |
| parent | Fix forward declaration order for s_GotSigWinch and SigWinchHandler (diff) | |
| parent | trace: declare Region event name fields as AnsiString (#1012) (diff) | |
| download | archived-zen-sb/zen-help.tar.xz archived-zen-sb/zen-help.zip | |
Merge branch 'main' into sb/zen-helpsb/zen-help
- Combine HelpCommand (this branch) with HistoryCommand (main) in zen CLI dispatcher
- Keep filter-aware TuiPickOne rewrite; adopt main's ASCII arrow glyphs in doc comment
Diffstat (limited to 'src/zenutil/windows')
| -rw-r--r-- | src/zenutil/windows/windowsservice.cpp | 39 |
1 files changed, 16 insertions, 23 deletions
diff --git a/src/zenutil/windows/windowsservice.cpp b/src/zenutil/windows/windowsservice.cpp index ebb88b018..383568650 100644 --- a/src/zenutil/windows/windowsservice.cpp +++ b/src/zenutil/windows/windowsservice.cpp @@ -16,7 +16,6 @@ SERVICE_STATUS gSvcStatus; SERVICE_STATUS_HANDLE gSvcStatusHandle; -HANDLE ghSvcStopEvent = NULL; void SvcInstall(void); @@ -205,21 +204,6 @@ WindowsService::SvcMain() ReportSvcStatus(SERVICE_START_PENDING, NO_ERROR, 3000); - // Create an event. The control handler function, SvcCtrlHandler, - // signals this event when it receives the stop control code. - - ghSvcStopEvent = CreateEvent(NULL, // default security attributes - TRUE, // manual reset event - FALSE, // not signaled - NULL); // no name - - if (ghSvcStopEvent == NULL) - { - ReportSvcStatus(SERVICE_STOPPED, GetLastError(), 0); - - return 1; - } - int ReturnCode = Run(); return ReturnCode; } @@ -549,9 +533,18 @@ ReportSvcStatus(DWORD dwCurrentState, DWORD dwWin32ExitCode, DWORD dwWaitHint) gSvcStatus.dwWaitHint = dwWaitHint; if (dwCurrentState == SERVICE_START_PENDING) + { gSvcStatus.dwControlsAccepted = 0; + } + else if (dwCurrentState == SERVICE_STOP_PENDING || dwCurrentState == SERVICE_STOPPED) + { + // We are already stopping/stopped - don't accept further control codes. + gSvcStatus.dwControlsAccepted = 0; + } else - gSvcStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP; + { + gSvcStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN; + } if ((dwCurrentState == SERVICE_RUNNING) || (dwCurrentState == SERVICE_STOPPED)) gSvcStatus.dwCheckPoint = 0; @@ -573,14 +566,14 @@ WindowsService::SvcCtrlHandler(DWORD dwCtrl) switch (dwCtrl) { case SERVICE_CONTROL_STOP: - ReportSvcStatus(SERVICE_STOP_PENDING, NO_ERROR, 0); + case SERVICE_CONTROL_SHUTDOWN: + // SCM gives us dwWaitHint milliseconds to complete the stop; 30s leaves + // plenty of headroom for the HTTP server and service state to tear down. + ReportSvcStatus(SERVICE_STOP_PENDING, NO_ERROR, 30000); - // Signal the service to stop. - - SetEvent(ghSvcStopEvent); + // The HTTP server run loops poll IsApplicationExitRequested(), so this + // flag is how we ask them to wind down. zen::RequestApplicationExit(0); - - ReportSvcStatus(gSvcStatus.dwCurrentState, NO_ERROR, 0); return; case SERVICE_CONTROL_INTERROGATE: |