Sebastian Lackner : advapi32: Do not stop service main thread as long as there are still running services.

Alexandre Julliard julliard at winehq.org
Wed Aug 17 10:24:24 CDT 2016


Module: wine
Branch: master
Commit: 2263baaf2e4d5e3325fb2339613a68a8a232923b
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=2263baaf2e4d5e3325fb2339613a68a8a232923b

Author: Sebastian Lackner <sebastian at fds-team.de>
Date:   Wed Aug 17 09:40:04 2016 +0200

advapi32: Do not stop service main thread as long as there are still running services.

Signed-off-by: Sebastian Lackner <sebastian at fds-team.de>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/advapi32/service.c | 33 +++++++++++++++++++++------------
 1 file changed, 21 insertions(+), 12 deletions(-)

diff --git a/dlls/advapi32/service.c b/dlls/advapi32/service.c
index d6bd14c..cd3cd2f 100644
--- a/dlls/advapi32/service.c
+++ b/dlls/advapi32/service.c
@@ -96,7 +96,7 @@ static CRITICAL_SECTION service_cs = { &service_cs_debug, -1, 0, 0, 0, 0 };
 static service_data **services;
 static unsigned int nb_services;
 static HANDLE service_event;
-static HANDLE stop_event;
+static BOOL stop_service;
 
 extern HANDLE CDECL __wine_make_process_system(void);
 
@@ -546,22 +546,21 @@ static BOOL service_run_main_thread(void)
     }
 
     service_event = CreateEventW( NULL, FALSE, FALSE, NULL );
-    stop_event = CreateEventW( NULL, FALSE, FALSE, NULL );
+    stop_service  = FALSE;
 
     /* FIXME: service_control_dispatcher should be merged into the main thread */
     wait_handles[0] = __wine_make_process_system();
     wait_handles[1] = CreateThread( NULL, 0, service_control_dispatcher, disp, 0, NULL );
     wait_handles[2] = service_event;
-    wait_handles[3] = stop_event;
 
     TRACE("Starting %d services running as process %d\n",
           nb_services, GetCurrentProcessId());
 
     /* wait for all the threads to pack up and exit */
-    for (;;)
+    while (!stop_service)
     {
         EnterCriticalSection( &service_cs );
-        for (i = 0, n = 4; i < nb_services && n < MAXIMUM_WAIT_OBJECTS; i++)
+        for (i = 0, n = 3; i < nb_services && n < MAXIMUM_WAIT_OBJECTS; i++)
         {
             if (!services[i]->thread) continue;
             wait_services[n] = i;
@@ -619,10 +618,6 @@ static BOOL service_run_main_thread(void)
         {
             continue;  /* rebuild the list */
         }
-        else if (ret == 3)
-        {
-            return TRUE;
-        }
         else if (ret < n)
         {
             i = wait_services[ret];
@@ -633,6 +628,8 @@ static BOOL service_run_main_thread(void)
         }
         else return FALSE;
     }
+
+    return TRUE;
 }
 
 /******************************************************************************
@@ -810,9 +807,21 @@ SetServiceStatus( SERVICE_STATUS_HANDLE hService, LPSERVICE_STATUS lpStatus )
         return FALSE;
     }
 
-    if (lpStatus->dwCurrentState == SERVICE_STOPPED) {
-        SetEvent(stop_event);
-        CloseServiceHandle((SC_HANDLE)hService);
+    if (lpStatus->dwCurrentState == SERVICE_STOPPED)
+    {
+        unsigned int i, count = 0;
+        EnterCriticalSection( &service_cs );
+        for (i = 0; i < nb_services; i++)
+        {
+            if (services[i]->handle == (SC_HANDLE)hService) continue;
+            if (services[i]->thread) count++;
+        }
+        if (!count)
+        {
+            stop_service = TRUE;
+            SetEvent( service_event );  /* notify the main loop */
+        }
+        LeaveCriticalSection( &service_cs );
     }
 
     return TRUE;




More information about the wine-cvs mailing list