mirror of
https://github.com/LizardByte/Sunshine.git
synced 2025-02-19 12:41:00 +00:00
Fix SunshineSvc hanging if an error occurs during startup (#598)
This commit is contained in:
parent
b1ac4bc57c
commit
8a99187562
@ -80,28 +80,43 @@ HANDLE OpenLogFileHandle() {
|
||||
}
|
||||
|
||||
VOID WINAPI ServiceMain(DWORD dwArgc, LPTSTR *lpszArgv) {
|
||||
stop_event = CreateEventA(NULL, TRUE, FALSE, NULL);
|
||||
if(stop_event == NULL) {
|
||||
service_status_handle = RegisterServiceCtrlHandlerEx(SERVICE_NAME, HandlerEx, NULL);
|
||||
if(service_status_handle == NULL) {
|
||||
// Nothing we can really do here but terminate ourselves
|
||||
ExitProcess(GetLastError());
|
||||
return;
|
||||
}
|
||||
|
||||
service_status_handle = RegisterServiceCtrlHandlerEx(SERVICE_NAME, HandlerEx, NULL);
|
||||
if(service_status_handle == NULL) {
|
||||
// Tell SCM we're starting
|
||||
service_status.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
|
||||
service_status.dwServiceSpecificExitCode = 0;
|
||||
service_status.dwWin32ExitCode = NO_ERROR;
|
||||
service_status.dwWaitHint = 0;
|
||||
service_status.dwControlsAccepted = 0;
|
||||
service_status.dwCheckPoint = 0;
|
||||
service_status.dwCurrentState = SERVICE_START_PENDING;
|
||||
SetServiceStatus(service_status_handle, &service_status);
|
||||
|
||||
stop_event = CreateEventA(NULL, TRUE, FALSE, NULL);
|
||||
if(stop_event == NULL) {
|
||||
// Tell SCM we failed to start
|
||||
service_status.dwWin32ExitCode = GetLastError();
|
||||
service_status.dwCurrentState = SERVICE_STOPPED;
|
||||
SetServiceStatus(service_status_handle, &service_status);
|
||||
return;
|
||||
}
|
||||
|
||||
auto log_file_handle = OpenLogFileHandle();
|
||||
if(log_file_handle == INVALID_HANDLE_VALUE) {
|
||||
// Tell SCM we failed to start
|
||||
service_status.dwWin32ExitCode = GetLastError();
|
||||
service_status.dwCurrentState = SERVICE_STOPPED;
|
||||
SetServiceStatus(service_status_handle, &service_status);
|
||||
return;
|
||||
}
|
||||
|
||||
// Tell SCM we're running
|
||||
service_status.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
|
||||
service_status.dwServiceSpecificExitCode = 0;
|
||||
service_status.dwWin32ExitCode = NO_ERROR;
|
||||
service_status.dwWaitHint = 0;
|
||||
// Tell SCM we're running (and stoppable now)
|
||||
service_status.dwControlsAccepted = SERVICE_ACCEPT_STOP;
|
||||
service_status.dwCheckPoint = 0;
|
||||
service_status.dwCurrentState = SERVICE_RUNNING;
|
||||
SetServiceStatus(service_status_handle, &service_status);
|
||||
|
||||
@ -162,8 +177,7 @@ VOID WINAPI ServiceMain(DWORD dwArgc, LPTSTR *lpszArgv) {
|
||||
SetServiceStatus(service_status_handle, &service_status);
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
int main(int argc, char *argv[]) {
|
||||
static const SERVICE_TABLE_ENTRY service_table[] = {
|
||||
{ (LPSTR)SERVICE_NAME, ServiceMain },
|
||||
{ NULL, NULL }
|
||||
|
Loading…
x
Reference in New Issue
Block a user