From 67795adae06c0f28346818bdd974597cd77a90f1 Mon Sep 17 00:00:00 2001 From: Iain Patterson Date: Wed, 1 Jan 2014 18:49:06 +0000 Subject: [PATCH] Legacy quick'n'dirtiness. On Windows 2000, StartService() and ControlService() return ERROR_IO_PENDING immediately. Later versions of Windows have a builtin timeout before they will return that error. As far as we're concerned, ERROR_IO_PENDING indicates that the service control was sent successfully so we simply override the error and return success. If NSSM's service management functionality is ever expanded we can take the time to handle service controls in a more robust way. --- service.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/service.cpp b/service.cpp index 621277d..d7c7e6e 100644 --- a/service.cpp +++ b/service.cpp @@ -907,6 +907,21 @@ int control_service(unsigned long control, int argc, TCHAR **argv) { CloseHandle(service_handle); CloseServiceHandle(services); + if (error == ERROR_IO_PENDING) { + /* + Older versions of Windows return immediately with ERROR_IO_PENDING + indicate that the operation is still in progress. Newer versions + will return it if there really is a delay. As far as we're + concerned the operation is a success. We don't claim to offer a + fully-feature service control method; it's just a quick 'n' dirty + interface. + + In the future we may identify and handle this situation properly. + */ + ret = 1; + error = ERROR_SUCCESS; + } + if (ret) { _tprintf(_T("%s: %s"), canonical_name, error_string(error)); return 0; @@ -949,6 +964,11 @@ int control_service(unsigned long control, int argc, TCHAR **argv) { CloseHandle(service_handle); CloseServiceHandle(services); + if (error == ERROR_IO_PENDING) { + ret = 1; + error = ERROR_SUCCESS; + } + if (ret) { _tprintf(_T("%s: %s"), canonical_name, error_string(error)); return 0; -- 2.20.1