From 466cac1f52c20e7655068a9b9faaa62c01517771 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Sun, 20 Apr 2014 15:47:57 +0200 Subject: [PATCH] Wait until the service has stopped in the uninstaller. Refs #4865 --- icinga-app/icinga.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/icinga-app/icinga.cpp b/icinga-app/icinga.cpp index 4b80fe3a3..1fc84b58a 100644 --- a/icinga-app/icinga.cpp +++ b/icinga-app/icinga.cpp @@ -471,12 +471,29 @@ static int SetupService(bool install, int argc, char **argv) for (int i = 0; i < argc; i++) szArgs += " " + Utility::EscapeShellArg(argv[i]); - SC_HANDLE schService = OpenService(schSCManager, "icinga2", DELETE | SERVICE_STOP); + SC_HANDLE schService = OpenService(schSCManager, "icinga2", DELETE | SERVICE_STOP | SERVICE_QUERY_STATUS); if (schService != NULL) { SERVICE_STATUS status; ControlService(schService, SERVICE_CONTROL_STOP, &status); + double start = Utility::GetTime(); + while (status.dwCurrentState != SERVICE_STOPPED) { + double end = Utility::GetTime(); + + if (end - start > 30) { + printf("Could not stop the service.\n"); + break; + } + + Utility::Sleep(5); + + if (!QueryServiceStatus(schService, &status)) { + printf("QueryServiceStatus failed (%d)\n", GetLastError()); + return 1; + } + } + if (!DeleteService(schService)) { printf("DeleteService failed (%d)\n", GetLastError()); CloseServiceHandle(schService); -- 2.40.0