advapi32[1/2]: return an error if we try to start an already running service

Mikolaj Zalewski mikolajz at google.com
Wed Aug 22 20:17:38 CDT 2007


Without not only we return a wrong value but we would call
service_set_process_id with a pid of 0.
-------------- next part --------------
From f7277cab1f9193d8a79f94acb9c4cf9e0b4d5775 Mon Sep 17 00:00:00 2001
From: Mikolaj Zalewski <mikolaj at zalewski.pl>
Date: Wed, 22 Aug 2007 18:08:29 -0700
Subject: [PATCH] advapi32: return an error if we try to start an already running service
---
 dlls/advapi32/service.c |   21 ++++++++++++++++-----
 1 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/dlls/advapi32/service.c b/dlls/advapi32/service.c
index 458653c..f922e62 100644
--- a/dlls/advapi32/service.c
+++ b/dlls/advapi32/service.c
@@ -454,7 +454,8 @@ static BOOL service_handle_start(HANDLE 
 
     if (service->thread)
     {
-        ERR("service is not stopped\n");
+        WARN("service is not stopped\n");
+        result = ERROR_SERVICE_ALREADY_RUNNING;
         goto end;
     }
 
@@ -503,7 +504,14 @@ static BOOL service_send_start_message(H
 
     r = WriteFile(pipe, ssi, sizeof *ssi + len*sizeof(WCHAR), &count, NULL);
     if (r)
+    {
         r = ReadFile(pipe, &result, sizeof result, &count, NULL);
+        if (r && result)
+        {
+            SetLastError(result);
+            r = FALSE;
+        }
+    }
 
     HeapFree(GetProcessHeap(),0,ssi);
 
@@ -1764,11 +1772,14 @@ BOOL WINAPI StartServiceW(SC_HANDLE hSer
         CloseHandle(handle);
     }
 
-    handle = service_open_pipe(hsvc->name);
-    if (handle != INVALID_HANDLE_VALUE)
+    if (r)
     {
-        service_set_processID(handle, dwProcessId, &dwResult);
-        CloseHandle(handle);
+        handle = service_open_pipe(hsvc->name);
+        if (handle != INVALID_HANDLE_VALUE)
+        {
+            service_set_processID(handle, dwProcessId, &dwResult);
+            CloseHandle(handle);
+        }
     }
 
     UnlockServiceDatabase( hLock );
-- 
1.4.1


More information about the wine-patches mailing list