From 9024e05e550b1b4a6a422639e9bbc699e5f53ea0 Mon Sep 17 00:00:00 2001 From: Eric Kohl Date: Sun, 8 Apr 2012 21:06:32 +0000 Subject: [PATCH] [SERVICES] - Make the handle to the shutdown event a global handle and set it when the service manager is being shut down. - Close the start event properly. svn path=/trunk/; revision=56337 --- reactos/base/system/services/services.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/reactos/base/system/services/services.c b/reactos/base/system/services/services.c index 300ea40eea5..d9b6f9ec68a 100644 --- a/reactos/base/system/services/services.c +++ b/reactos/base/system/services/services.c @@ -27,6 +27,7 @@ int WINAPI RegisterServicesProcess(DWORD ServicesProcessId); #define PIPE_TIMEOUT 1000 BOOL ScmShutdown = FALSE; +static HANDLE hScmShutdownEvent = NULL; /* FUNCTIONS *****************************************************************/ @@ -358,6 +359,9 @@ ShutdownHandlerRoutine(DWORD dwCtrlType) ScmAutoShutdownServices(); ScmShutdownServiceDatabase(); + + /* Set the shutdwon event */ + SetEvent(hScmShutdownEvent); } return TRUE; @@ -371,7 +375,6 @@ wWinMain(HINSTANCE hInstance, int nShowCmd) { HANDLE hScmStartEvent; - HANDLE hEvent; DWORD dwError; DPRINT("SERVICES: Service Control Manager\n"); @@ -395,6 +398,7 @@ wWinMain(HINSTANCE hInstance, if (dwError != ERROR_SUCCESS) { DPRINT1("SERVICES: failed to create SCM database (Error %lu)\n", dwError); + CloseHandle(hScmStartEvent); ExitThread(0); } @@ -431,19 +435,17 @@ wWinMain(HINSTANCE hInstance, DPRINT("SERVICES: Running.\n"); -#if 1 - hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); - if (hEvent) - WaitForSingleObject(hEvent, INFINITE); -#else - for (;;) - { - NtYieldExecution(); - } -#endif + /* Create the shutdown event and wait until it gets set */ + hScmShutdownEvent = CreateEvent(NULL, TRUE, FALSE, NULL); + if (hScmShutdownEvent) + WaitForSingleObject(hScmShutdownEvent, INFINITE); ScmDeleteNamedPipeCriticalSection(); + /* Close the shutdown event */ + CloseHandle(hScmShutdownEvent); + + /* Close the start event */ CloseHandle(hScmStartEvent); DPRINT("SERVICES: Finished.\n");