https://git.reactos.org/?p=reactos.git;a=commitdiff;h=8f911f21b8eb8178a0d09…
commit 8f911f21b8eb8178a0d09ec5fdf8eb664cf0733f
Author: Eric Kohl <eric.kohl(a)reactos.org>
AuthorDate: Sun Aug 5 20:02:22 2018 +0200
Commit: Eric Kohl <eric.kohl(a)reactos.org>
CommitDate: Sun Aug 5 20:02:22 2018 +0200
[SYSSETUP] SetupStartService: Wait until the service is running
---
dll/win32/syssetup/install.c | 26 ++++++++++++++++++++++++--
1 file changed, 24 insertions(+), 2 deletions(-)
diff --git a/dll/win32/syssetup/install.c b/dll/win32/syssetup/install.c
index 63fa4a28e9..e9b5745def 100644
--- a/dll/win32/syssetup/install.c
+++ b/dll/win32/syssetup/install.c
@@ -1508,7 +1508,9 @@ SetupStartService(
{
SC_HANDLE hManager = NULL;
SC_HANDLE hService = NULL;
+ SERVICE_STATUS ServiceStatus;
DWORD dwError = ERROR_SUCCESS;
+ DWORD dwRetries = 0;
hManager = OpenSCManagerW(NULL,
NULL,
@@ -1521,7 +1523,7 @@ SetupStartService(
hService = OpenServiceW(hManager,
lpServiceName,
- SERVICE_START);
+ SERVICE_START | (bWait) ? SERVICE_QUERY_STATUS : 0);
if (hService == NULL)
{
dwError = GetLastError();
@@ -1531,7 +1533,27 @@ SetupStartService(
if (!StartService(hService, 0, NULL))
{
dwError = GetLastError();
- goto done;
+ if (dwError != ERROR_SERVICE_ALREADY_RUNNING)
+ goto done;
+
+ if (bWait)
+ {
+ for (;;)
+ {
+ if (!QueryServiceStatus(hService, &ServiceStatus))
+ break;
+
+ if (ServiceStatus.dwCurrentState != SERVICE_START_PENDING)
+ break;
+
+ if (dwRetries == 30)
+ break;
+
+ dwRetries++;
+
+ Sleep(5000);
+ }
+ }
}
done: