| 244 | } |
| 245 | |
| 246 | HANDLE GetTerminationEventHandle(bool* isStartedByService) { |
| 247 | *isStartedByService = true; |
| 248 | HANDLE hEvent = CreateEvent(0, TRUE, FALSE, SERVICE_TERMINATION_EVENT_NAME); |
| 249 | if (!hEvent) { |
| 250 | return nullptr; |
| 251 | } |
| 252 | |
| 253 | if (GetLastError() != ERROR_ALREADY_EXISTS) { |
| 254 | *isStartedByService = false; |
| 255 | } |
| 256 | |
| 257 | return hEvent; |
| 258 | } |
| 259 | |
| 260 | bool CreateServiceTerminationThread(std::shared_ptr<logging::Logger> logger, HANDLE terminationEventHandle) { |
| 261 | // Get hService and monitor it - if service is terminated, then terminate current exe, otherwise the exe becomes unmanageable when service is restarted. |