https://git.reactos.org/?p=reactos.git;a=commitdiff;h=1f082ecc6842b818dfb92ec9bf41a90bf60382a3
commit 1f082ecc6842b818dfb92ec9bf41a90bf60382a3 Author: Eric Kohl <[email protected]> AuthorDate: Sun Jul 21 18:51:33 2019 +0200 Commit: Eric Kohl <[email protected]> CommitDate: Sun Jul 21 18:56:57 2019 +0200 [WMISERV][WUAUSERV] Stop the service if the stop event creation fails. --- base/services/wmisvc/wmisvc.c | 18 ++++++++++++------ base/services/wuauserv/wuauserv.c | 18 ++++++++++++------ 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/base/services/wmisvc/wmisvc.c b/base/services/wmisvc/wmisvc.c index 9ec17bb71b0..07c94eddd43 100644 --- a/base/services/wmisvc/wmisvc.c +++ b/base/services/wmisvc/wmisvc.c @@ -44,7 +44,7 @@ static WCHAR ServiceName[] = L"winmgmt"; static SERVICE_STATUS_HANDLE ServiceStatusHandle; static SERVICE_STATUS ServiceStatus; -static HANDLE ShutdownEvent; +static HANDLE hStopEvent = NULL; /* FUNCTIONS *****************************************************************/ @@ -85,7 +85,7 @@ ServiceControlHandler(DWORD dwControl, { case SERVICE_CONTROL_STOP: DPRINT1(" SERVICE_CONTROL_STOP received\n"); - SetEvent(ShutdownEvent); + SetEvent(hStopEvent); UpdateServiceStatus(SERVICE_STOP_PENDING); return ERROR_SUCCESS; @@ -107,7 +107,7 @@ ServiceControlHandler(DWORD dwControl, case SERVICE_CONTROL_SHUTDOWN: DPRINT1(" SERVICE_CONTROL_SHUTDOWN received\n"); - SetEvent(ShutdownEvent); + SetEvent(hStopEvent); UpdateServiceStatus(SERVICE_STOP_PENDING); return ERROR_SUCCESS; @@ -134,13 +134,19 @@ ServiceMain(DWORD argc, LPTSTR *argv) return; } - ShutdownEvent = CreateEventW(NULL, TRUE, FALSE, NULL); + hStopEvent = CreateEventW(NULL, TRUE, FALSE, NULL); + if (hStopEvent == NULL) + { + DPRINT1("CreateEvent() failed! (Error %lu)\n", GetLastError()); + goto done; + } UpdateServiceStatus(SERVICE_RUNNING); - WaitForSingleObject(ShutdownEvent, INFINITE); - CloseHandle(ShutdownEvent); + WaitForSingleObject(hStopEvent, INFINITE); + CloseHandle(hStopEvent); +done: UpdateServiceStatus(SERVICE_STOPPED); } diff --git a/base/services/wuauserv/wuauserv.c b/base/services/wuauserv/wuauserv.c index cd9062c1145..6ebc0809ec1 100644 --- a/base/services/wuauserv/wuauserv.c +++ b/base/services/wuauserv/wuauserv.c @@ -15,7 +15,7 @@ static WCHAR ServiceName[] = L"wuauserv"; static SERVICE_STATUS_HANDLE ServiceStatusHandle; static SERVICE_STATUS ServiceStatus; -static HANDLE exitEvent = NULL; +static HANDLE hStopEvent = NULL; /* FUNCTIONS *****************************************************************/ @@ -55,7 +55,7 @@ ServiceControlHandler(DWORD dwControl, { case SERVICE_CONTROL_STOP: DPRINT1("WU ServiceControlHandler() SERVICE_CONTROL_STOP received\n"); - SetEvent(exitEvent); + SetEvent(hStopEvent); UpdateServiceStatus(SERVICE_STOP_PENDING); return ERROR_SUCCESS; @@ -77,7 +77,7 @@ ServiceControlHandler(DWORD dwControl, case SERVICE_CONTROL_SHUTDOWN: DPRINT1("WU ServiceControlHandler() SERVICE_CONTROL_SHUTDOWN received\n"); - SetEvent(exitEvent); + SetEvent(hStopEvent); UpdateServiceStatus(SERVICE_STOP_PENDING); return ERROR_SUCCESS; @@ -104,13 +104,19 @@ ServiceMain(DWORD argc, LPTSTR *argv) return; } - exitEvent = CreateEventW(NULL, TRUE, FALSE, NULL); + hStopEvent = CreateEventW(NULL, TRUE, FALSE, NULL); + if (hStopEvent == NULL) + { + DPRINT1("CreateEvent() failed! (Error %lu)\n", GetLastError()); + goto done; + } UpdateServiceStatus(SERVICE_RUNNING); - WaitForSingleObject(exitEvent, INFINITE); - CloseHandle(exitEvent); + WaitForSingleObject(hStopEvent, INFINITE); + CloseHandle(hStopEvent); +done: UpdateServiceStatus(SERVICE_STOPPED); }
